Hi Anthony:

> isset($foo['bar'][1]['baz']) && is_array($foo['bar'][1])
> 
> You don't need to check each level.  Only the one above the key you're
> looking at.

Excellent thinking.  One hitch... that goes fatal in 5.3 if $foo is a string.
Here's how to write the test so it works the same way under 5.3 and 5.4:

<?php
function test2($id, $foo) {
    echo "ID $id -- ";
    var_dump(is_array($foo)
             && isset($foo['bar'][1]['baz']) && is_array($foo['bar'][1]));

    // The following goes fatal on test 80.
    //var_dump(isset($foo['bar'][1]['baz']) && is_array($foo['bar'][1]));
}
test2(10, array('bar' => array(1 => array('baz' => 'string'))));
test2(20, array('bar' => array(1 => array('boo' => 'string'))));
test2(30, array('bar' => array(1 => 'string')));
test2(40, array('bar' => array(2 => 'string')));
test2(50, array('boo' => array(1 => 'string')));
test2(60, array('bar' => 'string'));
test2(70, array('boo' => 'string'));
test2(80, 'string');
?>

Thanks,

--Dan

-- 
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
            data intensive web and database programming
                http://www.AnalysisAndSolutions.com/
 4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335 f: 718-854-0409

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to