PHP: testing for existence of a cell in a multidimensional array

Posted by gidireich on Stack Overflow See other posts from Stack Overflow or by gidireich
Published on 2011-01-02T01:30:06Z Indexed on 2011/01/02 1:54 UTC
Read the original article Hit count: 568

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about php

Related posts about multidimensional-array