I have an array with numerous dimensions, and I want to test for the existence of a cell.
The below cascaded approach, will be for sure a safe way to do it:
If you want to check $arr['dim1Key']['dim2Key']['dim3Key']
, to be safe you need to check if all arrays exist before dim3Key
. Then you can use array_key_exists
.
So yes, there is a simpler way using one single if
statement like the following:
if (isset($arr['dim1Key']['dim2Key']) &&
array_key_exists('dim3Key', $arr['dim1Key']['dim2Key'])) ...