Php array walk recursive
From w3cyberlearnings
Contents |
PHP function array_walk_recursive
This function is similar to the array_walk function, however array_walk_recursive() can walk with a deeper array. This function runs each array element (keys and values) to the user-defined function, and it returns TRUE or FALSE according to the statement defined within the user-defined function.
Syntax array_walk_recursive
- array: array input
- callback: user-defined function to process the array key and value.
- para (optional): user-defined parameter to be included with the callback function.
array_walk_recursive(array, callback, para);
Note
function callback($val, $key, $para) { statement }
Example 1
<?php function score_u($score, $name) { echo "{$name} scores {$score}<br/>"; } $score = array( 'Taylor' => 32, 'Lucas' => 12, 'Makayla' => 42, 'Jennifer' => 12, 'Group Lucas' => array('John' => 30, 'Mark' => 31) ); array_walk_recursive($score, "score_u"); ?>
Output
Taylor scores 32 Lucas scores 12 Makayla scores 42 Jennifer scores 12 John scores 30 Mark scores 31
Related Links
- array_change_key_case
- array_chunk
- array_combine
- array_count_values
- array_diff_assoc
- array_diff_key
- array_diff_uassoc
- array_diff_ukey
- array_diff
- array_fill_keys
- array_fill
- array_filter
- array_flip
- array_intersect_assoc
- array_intersect_key
- array_intersect_uassoc
- array_intersect_ukey
- array_intersect
- array_key_ exists
- array_keys