Jump to: navigation, search

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


Navigation
Web
SQL
MISC
References