if i'm accessing an index like that
$var = $final_Length_Array[1][0]['id'];
how to check whether the "id" key index exist in the array or not.
i tried to use function array_key_exists
but it seems to be working only on one dimension array.
i tried it like if(array_key_exists('id',$final_Length_Array)){
but it didn't work
i also tried isset to check whether there is a result or not but it didn't work also if(isset($final_Length_Array[1][0]['id'])){
any help i'll be appreciate it
Super hacky solution:
function array_key_exists_recursive($array, $key) {
return strpos(json_encode($array), "\"" . $key . "\":") !== false;
}
Better solution:
$array = ['a' => ['b' => 'c']];
function array_key_exists_recursive($key, $array) {
if (array_key_exists($key, $array)) {
return true;
}
foreach($array as $k => $value) {
if (is_array($value) && array_key_exists_recursive($key, $value)) {
return true;
}
}
return false;
}
var_dump(array_key_exists_recursive('b', $array));