Annotation of embedaddon/php/ext/standard/tests/array/array_map_basic.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test array_map() function : basic functionality
! 3: --FILE--
! 4: <?php
! 5: /* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] )
! 6: * Description: Applies the callback to the elements of the given arrays
! 7: * Source code: ext/standard/array.c
! 8: */
! 9:
! 10: echo "*** Testing array_map() : basic functionality ***\n";
! 11:
! 12: function multiply($p, $q) {
! 13: return ($p * $q);
! 14: }
! 15:
! 16: function square($p) {
! 17: return ($p * $p);
! 18: }
! 19:
! 20: function concatenate($a, $b) {
! 21: return "$a = $b";
! 22: }
! 23:
! 24: // integer array
! 25: $arr1 = array(1, 2, 3);
! 26: $arr2 = array(4, 5, 6);
! 27:
! 28: echo "-- With two integer array --\n";
! 29: var_dump( array_map('multiply', $arr1, $arr2) );
! 30:
! 31: echo "-- With single integer array --\n";
! 32: var_dump( array_map('square', $arr1) );
! 33:
! 34: // string array
! 35: $arr1 = array("one", "two");
! 36: $arr2 = array("single", "double");
! 37:
! 38: echo "-- With string array --\n";
! 39: var_dump( array_map('concatenate', $arr1, $arr2) );
! 40:
! 41: echo "Done";
! 42: ?>
! 43: --EXPECTF--
! 44: *** Testing array_map() : basic functionality ***
! 45: -- With two integer array --
! 46: array(3) {
! 47: [0]=>
! 48: int(4)
! 49: [1]=>
! 50: int(10)
! 51: [2]=>
! 52: int(18)
! 53: }
! 54: -- With single integer array --
! 55: array(3) {
! 56: [0]=>
! 57: int(1)
! 58: [1]=>
! 59: int(4)
! 60: [2]=>
! 61: int(9)
! 62: }
! 63: -- With string array --
! 64: array(2) {
! 65: [0]=>
! 66: string(12) "one = single"
! 67: [1]=>
! 68: string(12) "two = double"
! 69: }
! 70: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>