Answer the question
In order to leave comments, you need to log in
How to process the response through foreach?
Hello everyone, I ran into such a problem, there is a php code
$audio = json_decode(file_get_contents('https://api.vk.com/method/audio.get'. '?' .urldecode(http_build_query($audioget))), true);
Which makes a request to VK and receives audio in response. The response looks likeArray ( [response] => Array ( [count] => 130 [items] => Array ( [0] => Array ( [id] => 410351878 [owner_id] => 269325842 [artist] => Scorpions [title] => Under The Same Sun [duration] => 293 [date] => 1446625793 [url] => http://cs9-3v4.v
The question is how to convert everything to the form<div class="container_audio">
<div class="data_song">
<div class="title"></div>
<div class="artist"></div>
<div class="url"></div>
</div>
</div>
Answer the question
In order to leave comments, you need to log in
<?php if (!empty($audio['response']['items'])) { ?>
<div class="container_audio">
<?php foreach ($audio['response']['items'] as $item) { ?>
<div class="data_song">
<div class="title"><?= $item['title'] ?></div>
<div class="artist"><?= $item['artist'] ?></div>
<div class="url"><?= $item['url'] ?></div>
</div>
<?php } ?>
</div>
<?php } ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question