doufu1504 2012-04-08 20:02
浏览 50
已采纳

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
                )

        )
  • 写回答

1条回答 默认 最新

  • douhuai2015 2012-04-08 20:04
    关注
    <?php
    $result = array(...);
    
    foreach( $result['videos'] as $video )
    {
      // $video is each individual item in the videos array
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题