Return to array_walk_recursive_variation9.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / array |
1.1 misho 1: --TEST-- 2: Test array_walk_recursive() function : usage variations - different callback functions 3: --FILE-- 4: <?php 5: /* Prototype : 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 different types of callback functions to array_walk_recursive() 12: * without parameters 13: * with less and more parameters 14: */ 15: 16: echo "*** Testing array_walk_recursive() : callback function variation ***\n"; 17: 18: $input = array(array('Apple', 'Banana'), 'Mango', array('Orange')); 19: 20: echo "-- callback function with both parameters --\n"; 21: function callback_two_parameter($value, $key) 22: { 23: // dump the arguments to check that they are passed 24: // with proper type 25: var_dump($key); // key 26: var_dump($value); // value 27: echo "\n"; // new line to separate the output between each element 28: } 29: var_dump( array_walk_recursive($input, 'callback_two_parameter')); 30: 31: echo "-- callback function with only one parameter --\n"; 32: function callback_one_parameter($value) 33: { 34: // dump the arguments to check that they are passed 35: // with proper type 36: var_dump($value); // value 37: echo "\n"; // new line to separate the output between each element 38: } 39: var_dump( array_walk_recursive($input, 'callback_one_parameter')); 40: 41: echo "-- callback function without parameters --\n"; 42: function callback_no_parameter() 43: { 44: echo "callback3() called\n"; 45: } 46: var_dump( array_walk_recursive($input, 'callback_no_parameter')); 47: 48: echo "-- passing one more parameter to function with two parameters --\n"; 49: var_dump( array_walk_recursive($input, 'callback_two_parameter', 10)); 50: 51: echo "Done" 52: ?> 53: --EXPECTF-- 54: *** Testing array_walk_recursive() : callback function variation *** 55: -- callback function with both parameters -- 56: int(0) 57: string(5) "Apple" 58: 59: int(1) 60: string(6) "Banana" 61: 62: int(1) 63: string(5) "Mango" 64: 65: int(0) 66: string(6) "Orange" 67: 68: bool(true) 69: -- callback function with only one parameter -- 70: string(5) "Apple" 71: 72: string(6) "Banana" 73: 74: string(5) "Mango" 75: 76: string(6) "Orange" 77: 78: bool(true) 79: -- callback function without parameters -- 80: callback3() called 81: callback3() called 82: callback3() called 83: callback3() called 84: bool(true) 85: -- passing one more parameter to function with two parameters -- 86: int(0) 87: string(5) "Apple" 88: 89: int(1) 90: string(6) "Banana" 91: 92: int(1) 93: string(5) "Mango" 94: 95: int(0) 96: string(6) "Orange" 97: 98: bool(true) 99: Done