How to use the array_walk function in php
Today, I would like to share with you the relevant knowledge points about how to use the array_walk function in php. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.
1. Description
Array_walk uses callback functions to deal with the elements of the array. The difference between array_map and array_walk lies in the presence or absence of key.
This function returns bool. Therefore, it is necessary to cooperate with the reference value to directly change the original array to have a certain effect.
2. Grammar
Array_walk (array,myfunction,parameter...)
3. Parameters
Array is required.
Myfunction is required.
Parameter,... Optional.
4. Return value
Returns TRUE if successful, FALSE otherwise.
5. Examples
/ / use the elements in the array for some operation $arr = ['axiajughaojiaoyuanjiajie]; array_walk ($arr,function ($val,$key) {echo "{$key} is {$val}";}); / / return the result / / 0 is an is array_walk / change the value in the array, passing parameters with reference array_walk ($arr,function (& $val,$key) {$val. = $val;}); var_dump ($arr) / / array (size=3) / / 0 = > string 'aa' (length=2) / / 1 = > string' bb' (length=2) / / 2 = > string 'cc' (length=2) these are all the contents of this article "how to use array_walk functions in php". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.