note 116047 added to functions.arguments
| From: | HayleyWatson | Date: | Mon, 03 Nov 2014 07:21:12 +0000 |
| Subject: | note 116047 added to functions.arguments | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200771@lists.php.net to get a copy of this message | ||
An example is given in the user notes for array_map that transposes a rectangular array; it involves
unshifting a null onto the start of the array and then calling call_user_func_array.
With the parameter-unpacking "..." operator, modifying the array and calling array_map
indirectly is no longer needed. Instead of
<?php
$array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
array_unshift($array, null);
$transpose = call_user_func_array("array_map", $array);
?>
It's enough to write
<?php
$array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
$transpose = array_map(null, ...$array);
?>
----
Server IP: 120.138.27.69
Probable Submitter: 222.155.198.204
----
Manual Page -- http://php.net/manual/en/functions.arguments.php
Edit -- https://master.php.net/note/edit/116047
Del: integrated -- https://master.php.net/note/delete/116047/integrated
Del: useless -- https://master.php.net/note/delete/116047/useless
Del: bad code -- https://master.php.net/note/delete/116047/bad+code
Del: spam -- https://master.php.net/note/delete/116047/spam
Del: non-english -- https://master.php.net/note/delete/116047/non-english
Del: in docs -- https://master.php.net/note/delete/116047/in+docs
Del: other reasons-- https://master.php.net/note/delete/116047
Reject -- https://master.php.net/note/reject/116047
Search -- https://master.php.net/manage/user-notes.php