وظيفة PHP array_walk_recursive()
مثال
تطبيق دالة مستخدم مخصصة على كل عنصر في اللوحة:
<?php function myfunction($value,$key) { echo "مفتاح $key قيمته هي $value .<br>"; } $a1=array("a"=>"red","b"=>"green"); $a2=array($a1,"1"=>"blue","2"=>"yellow"); array_walk_recursive($a2,"myfunction"); ?>
Definition and Usage
The array_walk_recursive() function applies the user-defined function to each element in the array. In the function, the array key and value are parameters.
This function is similar to array_walk() The difference of the function lies in that it can operate on deeper arrays (an array contains another array).
Syntax
array_walk_recursive(array,myfunction,parameter...)
Parameters | Description |
---|---|
array | Required. Specifies the array. |
myfunction | Required. Specifies the name of the user-defined function. |
userdata,... | Optional. Specifies the user-defined function parameters. You can pass any number of parameters to this function. |
Description
With array_walk() Functions similar, the array_walk_recursive() function applies the callback function to each element in the array. The difference is that if the elements in the original array are also arrays, the callback function will be recursively called, that is, it will recursively go to a deeper array.
Typically,myfunction accepts two parameters.array The value of the parameter as the first, and the key name as the second. If optional parameters are provided userdata is passed as the third parameter to the callback function.
If the callback function needs to directly act on the values in the array, you can specify the first parameter of the callback function as a reference, so any changes to these elements will also change the original array itself.
Technical Details
Return Value: | Returns TRUE if successful, otherwise FALSE. |
PHP Version: | 5+ |