1--TEST-- 2Test 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 10echo "*** Testing array_map() : basic functionality ***\n"; 11 12function multiply($p, $q) { 13 return ($p * $q); 14} 15 16function square($p) { 17 return ($p * $p); 18} 19 20function 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 28echo "-- With two integer array --\n"; 29var_dump( array_map('multiply', $arr1, $arr2) ); 30 31echo "-- With single integer array --\n"; 32var_dump( array_map('square', $arr1) ); 33 34// string array 35$arr1 = array("one", "two"); 36$arr2 = array("single", "double"); 37 38echo "-- With string array --\n"; 39var_dump( array_map('concatenate', $arr1, $arr2) ); 40 41echo "Done"; 42?> 43--EXPECTF-- 44*** Testing array_map() : basic functionality *** 45-- With two integer array -- 46array(3) { 47 [0]=> 48 int(4) 49 [1]=> 50 int(10) 51 [2]=> 52 int(18) 53} 54-- With single integer array -- 55array(3) { 56 [0]=> 57 int(1) 58 [1]=> 59 int(4) 60 [2]=> 61 int(9) 62} 63-- With string array -- 64array(2) { 65 [0]=> 66 string(12) "one = single" 67 [1]=> 68 string(12) "two = double" 69} 70Done 71