PHP:循环多维数组 [英] PHP: Loop Through Multidimensional Array
本文介绍了PHP:循环多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一次只能循环一个部分来填充某些选项卡的内容。什么是最好的方式来循环只是视频
数组?
I need to be able to loop over only a section at a time to populate content for some Tabs. What would be the best way to loop over just the Videos
array?
这是我已经尝试过:
This is what I've tried:
foreach ($result['videos'] as $r) {
$content = '<tr>';
$content .= '<td>' . $r['id'] . '</td>';
$content .= '<td>' . $r['name'] . '</td>';
$content .= '<td>' . $r['body'] . '</td>';
$content .= '<td>' . $r['created'] . '</td>';
$content .= '<td>' . $r['modified'] . '</td>';
$content .= '</tr>';
echo $content;
}
Array
(
[images] => Array(...)
[videos] => Array
(
[0] => Array
(
[id] => 7
[type] => 2
[name] => My Video
[body] => my_video.flv
[created] => 0000-00-00 00:00:00
[modified] => 2012-04-07 00:00:00
)
[1] => Array
(
[id] => 13
[type] => 2
[name] => Yet another video
[body] => my_vid_man.flv
[created] => 0000-00-00 00:00:00
[modified] => 0000-00-00 00:00:00
)
[2] => Array
(
[id] => 25
[type] => 2
[name] => asasd
[body] => asdasd
[created] => 0000-00-00 00:00:00
[modified] => 0000-00-00 00:00:00
)
)
推荐答案
<?php
$result = array(...);
foreach( $result['videos'] as $video )
{
// $video is each individual item in the videos array
}
这篇关于PHP:循环多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文