array_walk() function in php
0 2128
PHP array_walk() function is used to walks through the entire PHP array. It is an inbuilt function of PHP. This function also contains a user-defined function in which conditions to be applied to every element of an array.
Syntax:
array_walk($array, user_function, $param...);
here,
- $array is a PHP array on which this function to be applied. It is mandatory
- user_function is a user-defined block of code that applied to every element of $array. It is also mandatory.
- $param represents one or more parameters for user-defined function. It is optional.
Example:
<?php function user_function($val,$key) { echo "The key $key has the value $val. <br>"; } $arr=array("fruit1"=>"apple","fruit2"=>"orange","fruit3"=>"fig","fruit4"=>"banana","fruit5"=>"guava"); array_walk($arr,"user_function"); ?>
Output:
Share:
Comments
Waiting for your comments