0

I have this json listed below. I was using json_decode to get some of the values. Such as getting the id value:

$decoded_array = json_decode($result, true);
            foreach($decoded_array['issue'] as $issues ){
                    $value[] = $issues["id"];

This method is working for getting the id value, however, I want to get the emailAddress values for both Bob and John. I believe you can get a single value by doing this:

$value[] = $issues["fields"][people][0][emailAddress];

Is it possible to get both email addresses in an efficient manner?

Edited --------

How would you get data with an expanded dataset? Example:

{
"startAt": 0,
"issue": [
    {
        "id": "51526",
        "fields": {
            "people": [
                {
                    "name": "bob",
                    "emailAddress": "[email protected]",
                    "displayName": "Bob Smith",
                },
                {
                    "name": "john",
                    "emailAddress": "[email protected]",
                    "displayName": "John Smith",
                }
            ],
            "skill": {
                "name": "artist",
                "id": "1"
            }
        }
    },
{
        "id": "2005",
        "fields": {
            "people": [
                {
                    "name": "jake",
                    "emailAddress": "[email protected]",
                    "displayName": "Jake Smith",
                },
                {
                    "name": "frank",
                    "emailAddress": "[email protected]",
                    "displayName": "Frank Smith",
                }
            ],
            "skill": {
                "name": "writer",
                "id": "2"
            }
        }
    }
]

}

I only want to extract the email addresses from both "fields". Is there an easy way to loop through all the "fields" to get "emailAddress" data?

1 Answer 1

2

You need to delve deeper into the array.

foreach ($decoded_array['issue'][0]['fields']['people'] as $person) {
  echo $person['emailAddress'];
}
Sign up to request clarification or add additional context in comments.

1 Comment

That does it! Thanks for the help

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.