I have a cURL command from an API which outputs JSON for me:
curl_setopt($ch, CURLOPT_URL, "https://url.com/Search/search/xref?user=[{%22USER%22:%22userName%22}]");
I then use PHP's jsondecode on the output:
$json = json_decode($answerSearch, true);
and my console's response tab gives me this for print_r($json);:
Array (
[Result] => Array
(
[Data] => Array
(
[ReqCompany] => ACME
[ReqLocation] =>
[Dot] => Array
(
[0] => Array
(
[ComID] => 20388417
[FavoriteColor] => Blue
)
[1] => Array
(
[ComID] => 20388418
[FavoriteColor] => Pink
)
[2] => Array
(
[ComID] => 20388419
[FavoriteColor] => Red
)
)
[XREFSearchOperation] => Exact
)
)
)
How do I write a foreach loop to go through each element of this array and output each `[FavoriteColor]'? I've done this many times with a simple array, but never a multi-dimensional one.
I've tried this:
foreach ($json as $i) {
echo $i['FavoriteColor'];
}
but my syntax is wrong.