PHP: testing for existence of a cell in a multidimensional array
- by gidireich
Hi,
I have an array with numerous dimensions. Want to test for existence of a cell.
The below cascaded approach, will be for sure a safe way to do it:
if (array_key_exists($arr, 'dim1Key'))
if (array_key_exists($arr['dim1Key'], 'dim2Key'))
if (array_key_exists($arr['dim1Key']['dim2Key'], 'dim3Key'))
echo "cell exists";
But it there a simpler way?
I'll go into more details about this:
1. Can I perform this check in one single statement?
2. Do I have to use array_key_exist or can I use something like isset? Will appreciate if someone explains when to use each and why
Thanks
Gidi