我的数组再次出现问题:( 我有这个:
Array
(
[results] => Array
(
[0] => Array
(
[backdrop_path] => htttp://link.com/img.jpg
[id] => 23951
[title] => 1
)
[1] => Array
(
[backdrop_path] => htttp://link.com/img.jpg
[id] => 23952
[title] => 2
)
[2] => Array
(
[backdrop_path] => htttp://link.com/img.jpg
[id] => 23953
[title] => 3
)
[3] => Array
(
[backdrop_path] => htttp://link.com/img.jpg
[id] => 23954
[title] => 4
)
)
)
如何将其转换为:
非常感谢你!
答案 0 :(得分:1)
使用foreach
echo '<ul>';
foreach ($array['results'] as $element) {
echo "<li>title: {$element['title']}</li>";
}
echo '</ul>';
答案 1 :(得分:1)
if (!empty($array['results'])){
echo '<ul>';
foreach ($array['results'] as $a){
echo "<li>title: {$a['title']}</li>";
}
echo '</ul>';
}
答案 2 :(得分:1)
我建议您使用array_map()代替foreach()
或for
循环。例如:
echo '<ul>';
array_map(function($v){echo '<li>Title: '.$v['title'].'</li>';}, $str['results']);
echo '</ul>';