foreach不在php中工作

时间:2014-10-15 10:14:52

标签: php arrays

我是PHP的新手,但我需要知道,如何在php中title获取volumeinfo

Array
(
    [kind] => books#volumes
    [totalItems] => 595
    [items] => Array
        (
            [0] => Array
                (
                    [kind] => books#volume
                    [id] => Aaug_RnI-xQC
                    [etag] => E1EIADudeHY
                    [selfLink] => https://www.googleapis.com/books/v1/volumes/Aaug_RnI-xQC
                    [volumeInfo] => Array
                        (
                            [title] => The Irresistible Rise of Harry Potter
                            [authors] => Array
                                (
                                    [0] => Andrew Blake
                                )

                            [publisher] => Verso
                            [publishedDate] => 2002
                            [description] => As the British state begins to unravel, and as journalists compete to pronounce on the death...

请帮帮我。

3 个答案:

答案 0 :(得分:0)

尝试单值

echo $array['items'][0]['volumeInfo']['title'];

或使用foreach

foreach($array['items'] as $items) { 
  echo $items['volumeInfo']['title']; 
}

答案 1 :(得分:0)

假设您的数组保存在$array

  • 循环浏览items
  • Echo volumnInfo.title

foreach($array['items'] as $items) { 
   echo $items['volumnInfo']['title'] . PHP_EOL; 
}

答案 2 :(得分:0)

您可以使用以下代码

foreach($array['items'] as $item) 
{ 
   echo $item['volumnInfo']['title']; 
}