Annotation of embedaddon/php/ext/standard/tests/array/array_walk_recursive_variation4.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test array_walk_recursive() function : usage variations - 'input' array with subarray
! 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: * Testing array_walk_recursive() with an array having subarrays as elements
! 12: */
! 13:
! 14: echo "*** Testing array_walk_recursive() : 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: */
! 22: function 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), array(1))
! 37: );
! 38:
! 39: var_dump( array_walk_recursive( $input, "callback"));
! 40:
! 41: echo "Done"
! 42: ?>
! 43: --EXPECTF--
! 44: *** Testing array_walk_recursive() : array with subarray ***
! 45: int(0)
! 46: int(1)
! 47:
! 48: int(0)
! 49: int(1)
! 50:
! 51: int(1)
! 52: int(2)
! 53:
! 54: int(2)
! 55: int(3)
! 56:
! 57: int(0)
! 58: string(5) "Mango"
! 59:
! 60: int(1)
! 61: string(6) "Orange"
! 62:
! 63: int(0)
! 64: int(1)
! 65:
! 66: int(1)
! 67: int(2)
! 68:
! 69: int(2)
! 70: int(3)
! 71:
! 72: int(0)
! 73: int(1)
! 74:
! 75: bool(true)
! 76: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>