Saturday, 28 July 2012

phph Array dereferencing

<?phpfunction getArray() {
    return array(
123);
}
// on PHP 5.4$secondElement getArray()[1];// previously$tmp getArray();$secondElement $tmp[1];// orlist(, $secondElement) = getArray();?>






// previously
$tmp = getArray();
$firstElement = $tmp[0];
$secondElement = $tmp[1];

// or
var_dump (list($firstElement, $secondElement) = getArray());

echo '**'.$firstElement;
echo '**'.$secondElement;



 
Note:
Attempting to access an array key which has not been defined is the same as accessing any other undefined variable: an E_NOTICE-level error message will be issued, and the result will be NULL.

No comments:

Post a Comment