1--TEST-- 2Test array_map() function : usage variations - associative array with different keys 3--FILE-- 4<?php 5/* 6 * Test array_map() by passing associative array with different keys for $arr1 argument 7 */ 8 9echo "*** Testing array_map() : associative array with diff. keys for 'arr1' argument ***\n"; 10 11function callback($a) 12{ 13 return ($a); 14} 15 16// get an unset variable 17$unset_var = 10; 18unset ($unset_var); 19 20// get a resource variable 21$fp = fopen(__FILE__, "r"); 22 23// get a class 24class classA{ 25 public function __toString(){ 26 return "Class A object"; 27 } 28} 29 30// get a heredoc string 31$heredoc = <<<EOT 32Hello world 33EOT; 34 35// initializing the array 36$arrays = array ( 37 38 // empty array 39/*1*/ array(), 40 41 // arrays with integer keys 42/*2*/ array(0 => "0"), 43 array(1 => "1"), 44 array(1 => "1", 2 => "2", 3 => "3", 4 => "4"), 45 46 // arrays with string keys 47 array('\tHello' => 111, 're\td' => 'color', '\v\fworld' => 2.2, 'pen\n' => 33), 48/*8*/ array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 33), 49 array("hello", $heredoc => "string"), // heredoc 50 51 // array with object, unset variable and resource variable 52 array(@$unset_var => "hello", $fp => 'resource'), 53 54 // array with mixed values 55/*11*/ array('hello' => 1, "fruit" => 2.2, 56 $fp => 'resource', 133 => "int", 57 @$unset_var => "unset", $heredoc => "heredoc") 58); 59 60// loop through the various elements of $arrays to test array_map() 61$iterator = 1; 62foreach($arrays as $arr1) { 63 echo "-- Iteration $iterator --\n"; 64 var_dump( array_map('callback', $arr1) ); 65 $iterator++; 66} 67 68echo "Done"; 69?> 70--EXPECTF-- 71*** Testing array_map() : associative array with diff. keys for 'arr1' argument *** 72 73Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d 74 75Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d 76-- Iteration 1 -- 77array(0) { 78} 79-- Iteration 2 -- 80array(1) { 81 [0]=> 82 string(1) "0" 83} 84-- Iteration 3 -- 85array(1) { 86 [1]=> 87 string(1) "1" 88} 89-- Iteration 4 -- 90array(4) { 91 [1]=> 92 string(1) "1" 93 [2]=> 94 string(1) "2" 95 [3]=> 96 string(1) "3" 97 [4]=> 98 string(1) "4" 99} 100-- Iteration 5 -- 101array(4) { 102 ["\tHello"]=> 103 int(111) 104 ["re\td"]=> 105 string(5) "color" 106 ["\v\fworld"]=> 107 float(2.2) 108 ["pen\n"]=> 109 int(33) 110} 111-- Iteration 6 -- 112array(4) { 113 [" Hello"]=> 114 int(111) 115 ["re d"]=> 116 string(5) "color" 117 ["world"]=> 118 float(2.2) 119 ["pen 120"]=> 121 int(33) 122} 123-- Iteration 7 -- 124array(2) { 125 [0]=> 126 string(5) "hello" 127 ["Hello world"]=> 128 string(6) "string" 129} 130-- Iteration 8 -- 131array(2) { 132 [""]=> 133 string(5) "hello" 134 [5]=> 135 string(8) "resource" 136} 137-- Iteration 9 -- 138array(6) { 139 ["hello"]=> 140 int(1) 141 ["fruit"]=> 142 float(2.2) 143 [5]=> 144 string(8) "resource" 145 [133]=> 146 string(3) "int" 147 [""]=> 148 string(5) "unset" 149 ["Hello world"]=> 150 string(7) "heredoc" 151} 152Done 153