note 43757 deleted from function.array-map by cmb
| From: | cmb@php.net | Date: | Sun, 25 Aug 2019 09:12:36 +0000 |
| Subject: | note 43757 deleted from function.array-map by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212004@lists.php.net to get a copy of this message | ||
Note Submitter: nd0 at gmx dot de
----
array_map works also fine with create_function:
<?php
$a = array(1, 2, 3, 4, 5);
$b = array_map(create_function('$n', 'return $n*$n*$n;'), $a);
print_r($b);
?>
if you want to manipulate the elements of the array, instead to on a copy,
than take a look at array_walk:
<?php
$a = array(1, 2, 3, 4, 5);
array_walk($a, create_function('&$n', '$n = $n*$n*$n;'));
print_r($a);
?>
The Result of both is:
Array
(
[0] => 1
[1] => 8
[2] => 27
[3] => 64
[4] => 125
)