1--TEST-- 2Test array_map() function : usage variations - references 3--FILE-- 4<?php 5 6/* Prototype : array array_map(mixed callback, array input1 [, array input2 ,...]) 7 * Description: Applies the callback to the elements in given arrays. 8 * Source code: ext/standard/array.c 9*/ 10 11echo "*** Testing array_map() : references ***\n"; 12$arr = array("k1" => "v1","k2"=>"v2"); 13$arr[]=&$arr["k1"]; 14$arr[]=&$arr; 15function cb1 ($a) {var_dump ($a);return array ($a);}; 16function cb2 (&$a) {var_dump ($a);return array (&$a);}; 17var_dump( array_map("cb1", $arr)); 18var_dump( array_map("cb2", $arr,$arr)); 19var_dump( array_map(null, $arr)); 20var_dump( array_map(null, $arr, $arr)); 21 22// break cycles 23$arr[0] = null; 24$arr[1] = null; 25 26echo "Done"; 27?> 28 29--EXPECT-- 30*** Testing array_map() : references *** 31string(2) "v1" 32string(2) "v2" 33string(2) "v1" 34array(4) { 35 ["k1"]=> 36 &string(2) "v1" 37 ["k2"]=> 38 string(2) "v2" 39 [0]=> 40 &string(2) "v1" 41 [1]=> 42 &array(4) { 43 ["k1"]=> 44 &string(2) "v1" 45 ["k2"]=> 46 string(2) "v2" 47 [0]=> 48 &string(2) "v1" 49 [1]=> 50 *RECURSION* 51 } 52} 53array(4) { 54 ["k1"]=> 55 array(1) { 56 [0]=> 57 string(2) "v1" 58 } 59 ["k2"]=> 60 array(1) { 61 [0]=> 62 string(2) "v2" 63 } 64 [0]=> 65 array(1) { 66 [0]=> 67 string(2) "v1" 68 } 69 [1]=> 70 array(1) { 71 [0]=> 72 array(4) { 73 ["k1"]=> 74 &string(2) "v1" 75 ["k2"]=> 76 string(2) "v2" 77 [0]=> 78 &string(2) "v1" 79 [1]=> 80 *RECURSION* 81 } 82 } 83} 84string(2) "v1" 85string(2) "v2" 86string(2) "v1" 87array(4) { 88 ["k1"]=> 89 &string(2) "v1" 90 ["k2"]=> 91 string(2) "v2" 92 [0]=> 93 &string(2) "v1" 94 [1]=> 95 &array(4) { 96 ["k1"]=> 97 &string(2) "v1" 98 ["k2"]=> 99 string(2) "v2" 100 [0]=> 101 &string(2) "v1" 102 [1]=> 103 *RECURSION* 104 } 105} 106array(4) { 107 [0]=> 108 array(1) { 109 [0]=> 110 &string(2) "v1" 111 } 112 [1]=> 113 array(1) { 114 [0]=> 115 string(2) "v2" 116 } 117 [2]=> 118 array(1) { 119 [0]=> 120 &string(2) "v1" 121 } 122 [3]=> 123 array(1) { 124 [0]=> 125 &array(4) { 126 ["k1"]=> 127 &string(2) "v1" 128 ["k2"]=> 129 string(2) "v2" 130 [0]=> 131 &string(2) "v1" 132 [1]=> 133 *RECURSION* 134 } 135 } 136} 137array(4) { 138 ["k1"]=> 139 &string(2) "v1" 140 ["k2"]=> 141 string(2) "v2" 142 [0]=> 143 &string(2) "v1" 144 [1]=> 145 &array(4) { 146 ["k1"]=> 147 &string(2) "v1" 148 ["k2"]=> 149 string(2) "v2" 150 [0]=> 151 &string(2) "v1" 152 [1]=> 153 *RECURSION* 154 } 155} 156array(4) { 157 [0]=> 158 array(2) { 159 [0]=> 160 &string(2) "v1" 161 [1]=> 162 &string(2) "v1" 163 } 164 [1]=> 165 array(2) { 166 [0]=> 167 string(2) "v2" 168 [1]=> 169 string(2) "v2" 170 } 171 [2]=> 172 array(2) { 173 [0]=> 174 &string(2) "v1" 175 [1]=> 176 &string(2) "v1" 177 } 178 [3]=> 179 array(2) { 180 [0]=> 181 &array(4) { 182 ["k1"]=> 183 &string(2) "v1" 184 ["k2"]=> 185 string(2) "v2" 186 [0]=> 187 &string(2) "v1" 188 [1]=> 189 *RECURSION* 190 } 191 [1]=> 192 &array(4) { 193 ["k1"]=> 194 &string(2) "v1" 195 ["k2"]=> 196 string(2) "v2" 197 [0]=> 198 &string(2) "v1" 199 [1]=> 200 *RECURSION* 201 } 202 } 203} 204Done 205