Add array dereferencing to array docs

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@323755 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Nikita Popov 2012-03-02 00:34:47 +00:00
parent 2063e436c3
commit 63f0c045f9

View file

@ -296,6 +296,34 @@ string(3) "foo"
</screen>
</example>
<para>
As of PHP 5.4 it is possible to array dereference the result of a function or method
call directly. Before it was only possible using a temporary variable.
</para>
<example>
<title>Array dereferencing</title>
<programlisting role="php">
<![CDATA[
<?php
function getArray() {
return array(1, 2, 3);
}
// on PHP 5.4
$secondElement = getArray()[1];
// previously
$tmp = getArray();
$secondElement = $tmp[1];
// or
list(, $secondElement) = getArray();
?>
]]>
</programlisting>
</example>
<note>
<para>
Attempting to access an array key which has not been defined is