English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The array_walk() function uses a user-defined function to perform callback processing on each element of the array
array_walk ( $array, $funcname [, $parameter] );
Apply the user-defined function funcname to each element of the array.
array_walk() is not affected by the internal array pointer of the array. array_walk() will traverse the entire array regardless of the pointer position.
Returns TRUE on success, or FALSE on failure.
Serial Number | Parameters and Description |
---|---|
1 | array (required) It specifies an array. |
2 | funcname (required) The name of the user-defined function. |
3 | Parameter (optional) It specifies a parameter for a user-defined function. |
Use array_walk() function to get each element of the array
<?php function call_back_function($value,$key) { echo "The value of key $key is $value \n"; } $input = array("a"=>"green", "b"=>"brown", "c"=>"blue", "red"); array_walk($input,"call_back_function"); ?>Test and see‹/›
Output result:
The value of key a is green The value of key b is brown The value of key c is blue The value of key 0 is red