A
A
Anton2018-06-26 20:23:11
PHP
Anton, 2018-06-26 20:23:11

Does not display a list of comments VK API PHP, how to do?

Here is my code for displaying comments.

$gid = $_GET['gid'];
   $pid = $_GET['pid'];
$api = file_get_contents("https://api.vk.com/method/wall.getComments?owner_id=-".$gid."&post_id=".$pid."&access_token=".$token."&count=10&v=5.58");
$wall = json_decode($api,true);
foreach ($wall['response'] as $items => $result) {
  echo $result['text'];
}

but it doesn't display comments.
if you print an array like this print_r($wall); the following is obtained.
Array
(
    [response] => Array
        (
            [count] => 7
            [items] => Array
                (
                    [0] => Array
                        (
                            [id] => 174664
                            [from_id] => 103055504
                            [date] => 1530022656
                            [text] => Это где, кто знает?
                        )

                    [1] => Array
                        (
                            [id] => 174667
                            [from_id] => 52254070
                            [date] => 1530023698
                            [text] => [id103055504|Артур], Опук
                            [reply_to_user] => 103055504
                            [reply_to_comment] => 174664
                        )

                    [2] => Array
                        (
                            [id] => 174668
                            [from_id] => 103055504
                            [date] => 1530023736
                            [text] => [id52254070|Евгений], спасибо
                            [reply_to_user] => 52254070
                            [reply_to_comment] => 174667
                        )

how to make it output comments exactly in the foreach loop, I need the loop

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2018-06-26
Veida @aveyda7

foreach ($wall['response']['items'] as => $item) {...}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question