PHP 8.5.0 Alpha 1 available for testing

Voting

: eight minus two?
(Example: nine)

The Note You're Voting On

arekandrei at yandex dot ru
15 years ago
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;
});
?>

<< Back to user notes page

To Top