0

Any idea how to access creator with foreach? I receive this as a result from the linkedin groups API and want to iterate through it, after joining the first level with foreach($data as $value) - I am not sure how to iterate through the second and third array to access the values for 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
            )

    )

  )

best

M

2 Answers 2

1

Since 5.5, you can use in this case array_column:

$creators =  array_column($data['values'],'creator');
Sign up to request clarification or add additional context in comments.

Comments

1

This will create an array of creators:

$creators = array();

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.