svn: /phpdoc/en/trunk/language/types/ array.xml
| From: | Nikita Popov | Date: | Fri, 02 Mar 2012 00:34:47 +0000 |
| Subject: | svn: /phpdoc/en/trunk/language/types/ array.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-9759@lists.php.net to get a copy of this message | ||
nikic Fri, 02 Mar 2012 00:34:47 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=323755
Log:
Add array dereferencing to array docs
Changed paths:
U phpdoc/en/trunk/language/types/array.xml
Modified: phpdoc/en/trunk/language/types/array.xml
===================================================================
--- phpdoc/en/trunk/language/types/array.xml 2012-03-02 00:29:49 UTC (rev 323754)
+++ phpdoc/en/trunk/language/types/array.xml 2012-03-02 00:34:47 UTC (rev 323755)
@@ -296,6 +296,34 @@
</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