note 95437 added to function.array-walk
| From: | arekandrei at yandex dot ru | Date: | Sun, 03 Jan 2010 15:30:38 +0000 |
| Subject: | note 95437 added to function.array-walk | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-164563@lists.php.net to get a copy of this message | ||
You can use lambda function as a second parameter:
<?php
array_walk($myArray, function(&$value, $key){
// if you want to change array values then "&" before the $value is mandatory.
});
?>
Example (multiply positive values by two):
<?php
$myArray = array(1, 2, 3, 4, 5);
array_walk($myArray, function(&$value, $index){
if ($value > 0) $value *= 2;
});
?>
----
Server IP: 93.93.89.253
Probable Submitter: 194.220.83.177
----
Manual Page -- http://www.php.net/manual/en/function.array-walk.php
Edit -- https://master.php.net/note/edit/95437
Del: integrated -- https://master.php.net/note/delete/95437/integrated
Del: useless -- https://master.php.net/note/delete/95437/useless
Del: bad code -- https://master.php.net/note/delete/95437/bad+code
Del: spam -- https://master.php.net/note/delete/95437/spam
Del: non-english -- https://master.php.net/note/delete/95437/non-english
Del: in docs -- https://master.php.net/note/delete/95437/in+docs
Del: other reasons-- https://master.php.net/note/delete/95437
Reject -- https://master.php.net/note/reject/95437
Search -- https://master.php.net/manage/user-notes.php