note 114970 added to function.array-map
| From: | JacobA dot Barber at yahoo dot com | Date: | Wed, 07 May 2014 16:27:07 +0000 |
| Subject: | note 114970 added to function.array-map | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-199478@lists.php.net to get a copy of this message | ||
Here is an example for php 5.4 and greater, using a closure:
<?php
$myList = [1,2,3,4];
$mappedList = array_map(function($value){
return $value * 2;
}, $myList);
var_dump($mappedList);
array(4) {
[0]=>int(2)
[1]=>int(4)
[2]=>int(6)
[3]=>int(8)
}
?>
This is useful when you don't want/need to define a function just so it can be used with the
map function.
----
Server IP: 72.52.91.14
Probable Submitter: 71.252.134.63
----
Manual Page -- http://php.net/manual/en/function.array-map.php
Edit -- https://master.php.net/note/edit/114970
Del: integrated -- https://master.php.net/note/delete/114970/integrated
Del: useless -- https://master.php.net/note/delete/114970/useless
Del: bad code -- https://master.php.net/note/delete/114970/bad+code
Del: spam -- https://master.php.net/note/delete/114970/spam
Del: non-english -- https://master.php.net/note/delete/114970/non-english
Del: in docs -- https://master.php.net/note/delete/114970/in+docs
Del: other reasons-- https://master.php.net/note/delete/114970
Reject -- https://master.php.net/note/reject/114970
Search -- https://master.php.net/manage/user-notes.php