mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
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:
parent
2063e436c3
commit
63f0c045f9
1 changed files with 28 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue