[80538] Shorthand syntax for array destruction (#477)

* Shorthand syntax for array destruction

* Remove reference to PHP 7.0 or lower

* Bring back mention of list() prior to 7.1.0

* Replace array destruction with destructuring

Co-authored-by: Kamil Tekiela <tekiela246@gmail.com>

Co-authored-by: Anna Filina <afilina@gmail.com>
Co-authored-by: Kamil Tekiela <tekiela246@gmail.com>
This commit is contained in:
Marco Aurélio Deleu 2021-08-17 18:10:06 +02:00 committed by GitHub
parent 65f1e1978c
commit 1499a2369c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -739,9 +739,14 @@ echo square(4); // outputs '16'.
<?php
function small_numbers()
{
return array (0, 1, 2);
return [0, 1, 2];
}
list ($zero, $one, $two) = small_numbers();
// Array destructuring will collect each member of the array individually
[$zero, $one, $two] = small_numbers();
// Prior to 7.1.0, the only equivalent alternative is using list() construct
list($zero, $one, $two) = small_numbers();
?>
]]>
</programlisting>