This is my sample array value returned
array:3 [▼
"Status" => array:1 [▼
0 => "200"
]
"Data" => array:1 [▼
0 => array:1 [▼
0 => array:2 [▼
"sellerId" => array:1 [▼
0 => "TEST01"
]
"currency" => array:1 [▼
0 => "USD"
]
]
]
]
"Date" => array:1 [▼
0 => "Dec 31 2019"
]
]
My sample code to retrieve the value from the array above
foreach($json_array as $key => $json) {
if($key == "Status") {
$status = $json[0];
} else if ($key == "Date") {
$date = $json[0];
} else {
dd($json[0][0]['sellerId'][0]);
}
}
I am using the method above to retrieve the value from multidimensional array. Is there any better approaches that i can use to achieve my way?
if (!empty($json_array[0]['Status']) $status = $json_array[0]['Status'];etc. That allows you to compare each of three expected key-values in three lines of code. If you don't know whether 'Status' is going to be the 0th or the 1st etc. array element, maybe you need to restructure the input array (if you can) to something that can be more consistent.if(!empty({expr})just in case the input stream happens to be missing an expected key/value.