doumiang2297 2013-11-02 03:18
浏览 31
已采纳

如何循环遍历php数组的内容? [关闭]

I have a php array which I got as a response from a server so I can't change it,

print_r($array); // result is below

 array(
  'responseHeader'=>array(
    'status'=>0,
    'QTime'=>0,
    'params'=>array(
      'indent'=>'true',
      'q'=>'rajnikanth',
      '_'=>'1383362349068',
      'wt'=>'php')),
  'response'=>array('numFound'=>2,'start'=>0,'docs'=>array(
      array(
        'id'=>'31546690',
        'title'=>'Jayan quotes',
        '_version_'=>1450551735544184832),
      array(
        'id'=>'597727',
        'title'=>'List of Internet phenomena',
        '_version_'=>1450551735290429440))
  ))

How to access each of the title values in this array? I tried to use $array[0] but it erred out saying no offset set.

  • 写回答

2条回答 默认 最新

  • duanchun1852 2013-11-02 03:22
    关注
    foreach ($array['response']['docs'] as $doc) {
        echo $doc['title'];
    }
    

    $array appears to be an array of two keys, responseHeader and response. The response key contains a docs key, which is an array of arrays. Each of these arrays appears to have a title.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?