note 43757 added to function.array-map

From: Date: Fri, 02 Jul 2004 08:42:52 +0000
Subject: note 43757 added to function.array-map
Groups: php.notes 
Request: Send a blank email to php-notes+get-72313@lists.php.net to get a copy of this message
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 ) ---- Manual Page -- http://www.php.net/manual/en/function.array-map.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+43757 Delete -- http://master.php.net/manage/user-notes.php?action=delete+43757&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+43757&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#72313) next »