I have this array extract from Facebook Graph Api Json.
(array is cutted because I get error for much code)
Array
(
[0] => stdClass Object
(
[name] => My Account
[account_id] => 534543534543534534
[campaigns] => Array
(
[0] => stdClass Object
(
[id] => 6786546546546
)
)
[leadgen_forms] => Array
(
[0] => stdClass Object
(
[leads] => Array
(
[0] => stdClass Object
(
[created_time] => stdClass Object
(
January 25, 2018 => 2018-01-25 06:53:31
[timezone_type] => 1
[timezone] => +00:00
)
[id] => 546546546456453453
[field_data] => Array
(
[0] => stdClass Object
(
[name] => full_name
[values] => Array
(
[0] => John Doe
)
)
[1] => stdClass Object
(
[name] => email
[values] => Array
(
[0] => [email protected]
)
)
[2] => stdClass Object
(
[name] => phone_number
[values] => Array
(
[0] => +39342423423423234
)
)
[3] => stdClass Object
(
[name] => post_code
[values] => Array
(
[0] => 18916
)
)
)
)
)
[id] => 23423423423432423
)
[1] => stdClass Object
(
[leads] => Array
(
[0] => stdClass Object
(
[created_time] => stdClass Object
(
January 25, 2018 => 2017-12-29 12:11:49
[timezone_type] => 1
[timezone] => +00:00
)
[id] => 23423423423423423
[field_data] => Array
(
[0] => stdClass Object
(
[name] => email
[values] => Array
(
[0] => [email protected]
)
)
[1] => stdClass Object
(
[name] => phone_number
[values] => Array
(
[0] => +3923423423423
)
)
[2] => stdClass Object
(
[name] => post_code
[values] => Array
(
[0] => 81666
)
)
[3] => stdClass Object
(
[name] => full_name
[values] => Array
(
[0] => Marika Doe
)
)
)
)
)
[id] => 335264990275802
)
)
[id] => act_129367037453298
)
)
This is my ‘foreach code’, but I cannot understand make ‘foreach’ for get ‘John Doe full name’ from array.
I know that I should be make another ‘foreach’ into first ‘foreach’ but I no found solution.
$resultArray = json_decode($graphEdge, true);
foreach($someObject as $datum){
echo $datum->name;
echo "<br>";
foreach($datumas $values){
echo $values->name;
}
}
Can anyone help? Thanks!
2
Answers
You need to use two
foreach()
like below:-Beautify your json data here to understand how it mapped.
https://jsonformatter.org/json-editor
And use array_column() to get your work done!