php array_walk
$arr = array(1, 2, 3);
// Call function on every item.
// Sign $item as reference to work on original item.
array_walk($arr, function(&$item, $key, $myParam){
$item *= 2;
}, 'will be in myParam');
// $arr now is [2, 4, 6]
php array_walk
$arr = array(1, 2, 3);
// Call function on every item.
// Sign $item as reference to work on original item.
array_walk($arr, function(&$item, $key, $myParam){
$item *= 2;
}, 'will be in myParam');
// $arr now is [2, 4, 6]
php array walk
<?php
/*
* For One Dimensional Array
*/
$alphabets = array(
'a' => 'apple',
'b' => 'ball',
'c' => 'cat',
);
array_walk($alphabets, 'myFunc', 'for');
function myFunc($value, $key, $param)
{
echo "$key $param $value <br>";
}
?>
/*
Out Put:-
a for apple
b for ball
c for cat
*/
<?php
/*
* For Two Dimensional Arrays:- array_walk_recursive()
**/
$alphabets = array(
'a' => 'apple',
'b' => 'ball',
'c' => 'cat',
array(
'd' => 'dog',
'e' => 'elephant',
)
);
array_walk_recursive($alphabets, 'myFunc2', 'for' );
function myFunc2($value, $key, $param){
echo "$key $param $value <br><br>";
};
?>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us