解析具有多个嵌套的PHP数组

解析具有多个嵌套的PHP数组,php,Php,我是一个新手,正在寻找解析PHP数组的帮助。我已生成以下数组,并将其保存在中: $items = $pocket->retrieve($params, $accessToken); 如您所见,每个项目都有一个状态属性,该属性为0或1。我正在寻找一种简单的方法来循环浏览每一项,找出有多少项状态为0,有多少项状态为1 我曾尝试使用一个简单的foreach,但没有成功。问题是,没有返回任何内容,因此我认为我没有正确解析数组 如果我做一个简单的打印,它会打印出数组 print_r($items)

我是一个新手,正在寻找解析PHP数组的帮助。我已生成以下数组,并将其保存在中:

$items = $pocket->retrieve($params, $accessToken);
如您所见,每个项目都有一个状态属性,该属性为0或1。我正在寻找一种简单的方法来循环浏览每一项,找出有多少项状态为0,有多少项状态为1

我曾尝试使用一个简单的foreach,但没有成功。问题是,没有返回任何内容,因此我认为我没有正确解析数组

如果我做一个简单的打印,它会打印出数组

print_r($items); 
到目前为止,我所拥有的:

$items = $pocket->retrieve($params, $accessToken);
$hasRead = 0;
$hasNotRead = 0;

foreach ($items as $key) {

    if ($key["status"] == 1) {
        $hasRead++;
    }
    else {
        $hasNotRead++;
    }

    echo "Read = " . $hasRead;
    echo "Not Rad = " . $hasNotRead;

}
非常感谢任何帮助

Array
(
    [status] => 1
    [complete] => 1
    [list] => Array
        (
            [666040191] => Array
                (
                    [item_id] => 666040191
                    [resolved_id] => 666040191
                    [given_url] => https://medium.com/matter/my-life-with-piper-from-big-house-to-small-screen-592b35f5af94
                    [given_title] => The Other True Story Behind ‘Orange Is The New Black’
                    [favorite] => 0
                    [status] => 0
                    [time_added] => 1405415236
                    [time_updated] => 1405415236
                    [time_read] => 0
                    [time_favorited] => 0
                    [sort_id] => 0
                    [resolved_title] => My Life with Piper: From Big House to Small Screen
                    [resolved_url] => https://medium.com/matter/my-life-with-piper-from-big-house-to-small-screen-592b35f5af94
                    [excerpt] => I was 29 years old and living the dream, or at least my version of it, when everything changed. I was in love with an amazing woman and had a rent-controlled sublet in New York City’s West Village and a good job at a glossy magazine.
                    [is_article] => 1
                    [is_index] => 0
                    [has_video] => 0
                    [has_image] => 1
                    [word_count] => 10066
                )

            [665694007] => Array
                (
                    [item_id] => 665694007
                    [resolved_id] => 665694007
                    [given_url] => http://digg.com/video/weird-al-yankovic-parodies-pharrells-happy
                    [given_title] => http://digg.com/video/weird-al-yankovic-parodies-pharrells-happy
                    [favorite] => 0
                    [status] => 0
                    [time_added] => 1405415180
                    [time_updated] => 1405415180
                    [time_read] => 0
                    [time_favorited] => 0
                    [sort_id] => 1
                    [resolved_title] => Weird Al Yankovic Parodies Pharrell's 'Happy'
                    [resolved_url] => http://digg.com/video/weird-al-yankovic-parodies-pharrells-happy
                    [excerpt] => Weird Al does a one-shot spoof of Pharrell's ubiquitous "Happy" with some surprise help from a few celebrities.
                    [is_article] => 1
                    [is_index] => 0
                    [has_video] => 0
                    [has_image] => 0
                    [word_count] => 18
                )

            [664691248] => Array
                (
                    [item_id] => 664691248
                    [resolved_id] => 664691252
                    [given_url] => http://www.thedailybeast.com/articles/2014/07/13/an-investigation-into-the-delicious-origins-of-ice-cream.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+thedailybeast%2Farticles+%28The+Daily+Beast+-+Latest+Articles%29
                    [given_title] => http://www.thedailybeast.com/articles/2014/07/13/an-investigation-into-the-
                    [favorite] => 0
                    [status] => 0
                    [time_added] => 1405415169
                    [time_updated] => 1405415169
                    [time_read] => 0
                    [time_favorited] => 0
                    [sort_id] => 2
                    [resolved_title] => An Investigation Into the Delicious Origins of Ice Cream
                    [resolved_url] => http://www.thedailybeast.com/articles/2014/07/13/an-investigation-into-the-delicious-origins-of-ice-cream.html
                    [excerpt] => Thirty years ago this week, Ronald Reagan made perhaps the most momentous decision of his presidency. "Ice cream is a nutritious and wholesome food," he declared on July 9, 1984. "It enjoys a reputation as the perfect dessert and snack."
                    [is_article] => 1
                    [is_index] => 0
                    [has_video] => 0
                    [has_image] => 0
                    [word_count] => 1262
                )

        )

    [error] => 
    [search_meta] => Array
        (
            [search_type] => normal
        )

    [since] => 1405421539
)

我想你想迭代列表数组,对吗

$items = $pocket->retrieve($params, $accessToken);
$hasRead = 0;
$hasNotRead = 0;

foreach ($items['list'] as $key) { //Added list

    if ($key["status"] == 1) {
        $hasRead++;
    }
    else {
        $hasNotRead++;
    }

}

echo "Read = " . $hasRead;
echo "Not Rad = " . $hasNotRead;

是的,foreach循环是正确的方法。看起来您没有尝试任何操作,否则您会显示代码(!)请参阅我的编辑以包含我编写的代码。我认为我的foreach不能正常工作。另一个简单的问题是——如果我想弄清楚——“每天有多少篇文章被阅读”——这是否同样简单?有一个$list[time_read]值,所以我可以解析它们吗?