1--TEST-- 2Test array_walk_recursive() function : usage variations - anonymous callback function 3--FILE-- 4<?php 5/* Prototype : proto bool array_walk_recursive(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* Passing anonymous(run-time) callback function with following variations: 12* with one parameter 13* two parameters 14* three parameters 15* extra parameters 16* without parameters 17*/ 18 19echo "*** Testing array_walk_recursive() : anonymous function as callback ***\n"; 20 21$input = array( array(2, 5), array(10, 0)); 22 23echo "-- Anonymous function with one argument --\n"; 24var_dump( array_walk_recursive($input, create_function('$value', 'var_dump($value); echo "\n";'))); 25 26echo "-- Anonymous function with two arguments --\n"; 27var_dump( array_walk_recursive($input, create_function('$value, $key', 'var_dump($key); var_dump($value); echo "\n";'))); 28 29echo "-- Anonymous function with three arguments --\n"; 30var_dump( array_walk_recursive($input, create_function('$value, $key, $user_data', 'var_dump($key); var_dump($value); var_dump($user_data); echo "\n";'), 10)); 31 32echo "-- Anonymous function with one more argument --\n"; 33var_dump( array_walk_recursive($input, create_function('$value, $key, $user_data', 'var_dump($key); var_dump($value); var_dump($user_data); echo "\n";'), 20, 30)); 34 35echo "-- Anonymous function with null argument --\n"; 36var_dump( array_walk_recursive( $input, create_function(null, 'echo "1\n";'))); 37echo "Done" 38?> 39--EXPECTF-- 40*** Testing array_walk_recursive() : anonymous function as callback *** 41-- Anonymous function with one argument -- 42int(2) 43 44int(5) 45 46int(10) 47 48int(0) 49 50bool(true) 51-- Anonymous function with two arguments -- 52int(0) 53int(2) 54 55int(1) 56int(5) 57 58int(0) 59int(10) 60 61int(1) 62int(0) 63 64bool(true) 65-- Anonymous function with three arguments -- 66int(0) 67int(2) 68int(10) 69 70int(1) 71int(5) 72int(10) 73 74int(0) 75int(10) 76int(10) 77 78int(1) 79int(0) 80int(10) 81 82bool(true) 83-- Anonymous function with one more argument -- 84 85Warning: array_walk_recursive() expects at most 3 parameters, 4 given in %s on line %d 86NULL 87-- Anonymous function with null argument -- 881 891 901 911 92bool(true) 93Done 94