1--TEST-- 2Test array_walk() function : usage variations - 'input' array with subarray 3--FILE-- 4<?php 5/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) 6 * Description: Apply a user function to every member of an array 7 * Source code: ext/standard/array.c 8*/ 9 10/* 11 * Testing array_walk() with an array having subarrays as elements 12*/ 13 14echo "*** Testing array_walk() : array with subarray ***\n"; 15 16// callback function 17/* Prototype : callback(mixed $value, mixed $key) 18 * Parameters : $value - values in given 'input' array 19 * $key - keys in given 'input' array 20 * Description : It prints the count of an array elements, passed as argument 21 */ 22function callback($value, $key) 23{ 24 // dump the arguments to check that they are passed 25 // with proper type 26 var_dump($key); // key 27 var_dump($value); // value 28 echo "\n"; // new line to separate the output between each element 29} 30 31$input = array( 32 array(), 33 array(1), 34 array(1,2,3), 35 array("Mango", "Orange"), 36 array(array(1, 2, 3)) 37); 38 39var_dump( array_walk( $input, "callback")); 40 41echo "Done" 42?> 43--EXPECTF-- 44*** Testing array_walk() : array with subarray *** 45int(0) 46array(0) { 47} 48 49int(1) 50array(1) { 51 [0]=> 52 int(1) 53} 54 55int(2) 56array(3) { 57 [0]=> 58 int(1) 59 [1]=> 60 int(2) 61 [2]=> 62 int(3) 63} 64 65int(3) 66array(2) { 67 [0]=> 68 string(5) "Mango" 69 [1]=> 70 string(6) "Orange" 71} 72 73int(4) 74array(1) { 75 [0]=> 76 array(3) { 77 [0]=> 78 int(1) 79 [1]=> 80 int(2) 81 [2]=> 82 int(3) 83 } 84} 85 86bool(true) 87Done 88