使用 foreach php 遍历数组

iterate through array with foreach php

知道如何使用 foreach 访问创建者吗?我从 linkedin 组 API 收到此结果,并希望在使用 foreach($data as $value) 加入第一级后迭代它 - 我不确定如何迭代第二个和第三个数组访问 creator

的值
Array
(
[_total] => 4
[values] => Array
    (
        [0] => Array
            (
                [creator] => Array
                    (
                        [firstName] => Martin
                        [headline] => test1
                        [id] => DNz_ycOHn5
                        [lastName] => asdf
                        [pictureUrl] => https://media.licdn.com
                    )

                [summary] => hi summary
                [title] => hi title
            )

        [1] => Array
            (
                [creator] => Array
                    (
                        [firstName] => Martin
                        [headline] => test2
                        [id] => DNz_ycOHn5
                        [lastName] => asdf
                        [pictureUrl] => https://media.licdn.com
                    )

                [summary] => summary
                [title] => testpost
            )

        [2] => Array
            (
                [creator] => Array
                    (
                        [firstName] => Martin
                        [headline] => test3
                        [id] => DNz_ycOHn5
                        [lastName] => asdf
                        [pictureUrl] => https://media.licdn.com
                    )

                [summary] => 12312
                [title] => linkedinDEV
            )

        [3] => Array
            (
                [creator] => Array
                    (
                        [firstName] => Martin
                        [headline] => test4
                        [id] => DNz_ycOHn5
                        [lastName] => asdf
                        [pictureUrl] => https://media.licdn.com
                    )

                [summary] => test123
                [title] => Discussion Title
            )

    )

  )

最佳

这将创建一组创作者:

$creators = array();

foreach($data['values'] as $value) {
    $creators[] = $value['creator'];
}

// An array containing the creator information
var_dump($creators);

从 5.5 开始,您可以在这种情况下使用 array_column:

$creators =  array_column($data['values'],'creator');