1--TEST-- 2Test array_unshift() function : usage variations - heredoc strings for 'var' argument 3--FILE-- 4<?php 5/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...]) 6 * Description: Pushes elements onto the beginning of the array 7 * Source code: ext/standard/array.c 8*/ 9 10/* 11 * Testing the functionality of array_unshift() by passing different 12 * heredoc strings for $var argument that is prepended to the array 13 * passed through $array argument 14*/ 15 16echo "*** Testing array_unshift() : heredoc strings for \$var argument ***\n"; 17 18// heredoc with empty value 19$empty_string = <<<EOT 20EOT; 21 22// heredoc with blank line 23$blank_line = <<<EOT 24 25 26EOT; 27 28// heredoc with multiline string 29$multiline_string = <<<EOT 30hello world 31The big brown fox jumped over; 32the lazy dog 33This is a double quoted string 34EOT; 35 36// heredoc with different whitespaces 37$diff_whitespaces = <<<EOT 38hello\r world\t 391111\t\t != 2222\v\v 40heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces 41EOT; 42 43// heredoc with numeric values 44$numeric_string = <<<EOT 4511 < 12. 123 >22 462222 != 1111.\t 0000 = 0000\n 47EOT; 48 49// heredoc with quote chars & slash 50$quote_char_string = <<<EOT 51This's a string with quotes: 52"strings in double quote"; 53'strings in single quote'; 54this\line is single quoted /with\slashes 55EOT; 56 57// array to be passed to $array argument 58$array = array('f' => "first", "s" => 'second', 1, 2.222); 59 60// different heredoc strings to be passed to $var argument 61$vars = array( 62 $empty_string, 63 $blank_line, 64 $multiline_string, 65 $diff_whitespaces, 66 $numeric_string, 67 $quote_char_string 68); 69 70// loop through the various elements of $arrays to test array_unshift() 71$iterator = 1; 72foreach($vars as $var) { 73 echo "-- Iteration $iterator --\n"; 74 $temp_array = $array; // assign $array to another temporary $temp_array 75 76 /* with default argument */ 77 // returns element count in the resulting array after arguments are pushed to 78 // beginning of the given array 79 var_dump( array_unshift($temp_array, $var) ); 80 81 // dump the resulting array 82 var_dump($temp_array); 83 84 /* with all possible arguments */ 85 // returns element count in the resulting array after arguments are pushed to 86 // beginning of the given array 87 $temp_array = $array; 88 var_dump( array_unshift($temp_array, $var, "hello", 'world') ); 89 90 // dump the resulting array 91 var_dump($temp_array); 92 $iterator++; 93} 94 95echo "Done"; 96?> 97--EXPECT-- 98*** Testing array_unshift() : heredoc strings for $var argument *** 99-- Iteration 1 -- 100int(5) 101array(5) { 102 [0]=> 103 string(0) "" 104 ["f"]=> 105 string(5) "first" 106 ["s"]=> 107 string(6) "second" 108 [1]=> 109 int(1) 110 [2]=> 111 float(2.222) 112} 113int(7) 114array(7) { 115 [0]=> 116 string(0) "" 117 [1]=> 118 string(5) "hello" 119 [2]=> 120 string(5) "world" 121 ["f"]=> 122 string(5) "first" 123 ["s"]=> 124 string(6) "second" 125 [3]=> 126 int(1) 127 [4]=> 128 float(2.222) 129} 130-- Iteration 2 -- 131int(5) 132array(5) { 133 [0]=> 134 string(1) " 135" 136 ["f"]=> 137 string(5) "first" 138 ["s"]=> 139 string(6) "second" 140 [1]=> 141 int(1) 142 [2]=> 143 float(2.222) 144} 145int(7) 146array(7) { 147 [0]=> 148 string(1) " 149" 150 [1]=> 151 string(5) "hello" 152 [2]=> 153 string(5) "world" 154 ["f"]=> 155 string(5) "first" 156 ["s"]=> 157 string(6) "second" 158 [3]=> 159 int(1) 160 [4]=> 161 float(2.222) 162} 163-- Iteration 3 -- 164int(5) 165array(5) { 166 [0]=> 167 string(86) "hello world 168The big brown fox jumped over; 169the lazy dog 170This is a double quoted string" 171 ["f"]=> 172 string(5) "first" 173 ["s"]=> 174 string(6) "second" 175 [1]=> 176 int(1) 177 [2]=> 178 float(2.222) 179} 180int(7) 181array(7) { 182 [0]=> 183 string(86) "hello world 184The big brown fox jumped over; 185the lazy dog 186This is a double quoted string" 187 [1]=> 188 string(5) "hello" 189 [2]=> 190 string(5) "world" 191 ["f"]=> 192 string(5) "first" 193 ["s"]=> 194 string(6) "second" 195 [3]=> 196 int(1) 197 [4]=> 198 float(2.222) 199} 200-- Iteration 4 -- 201int(5) 202array(5) { 203 [0]=> 204 string(88) "hello 205 world 2061111 != 2222 207heredoc 208double quoted string. withdifferentwhitespaces" 209 ["f"]=> 210 string(5) "first" 211 ["s"]=> 212 string(6) "second" 213 [1]=> 214 int(1) 215 [2]=> 216 float(2.222) 217} 218int(7) 219array(7) { 220 [0]=> 221 string(88) "hello 222 world 2231111 != 2222 224heredoc 225double quoted string. withdifferentwhitespaces" 226 [1]=> 227 string(5) "hello" 228 [2]=> 229 string(5) "world" 230 ["f"]=> 231 string(5) "first" 232 ["s"]=> 233 string(6) "second" 234 [3]=> 235 int(1) 236 [4]=> 237 float(2.222) 238} 239-- Iteration 5 -- 240int(5) 241array(5) { 242 [0]=> 243 string(44) "11 < 12. 123 >22 2442222 != 1111. 0000 = 0000 245" 246 ["f"]=> 247 string(5) "first" 248 ["s"]=> 249 string(6) "second" 250 [1]=> 251 int(1) 252 [2]=> 253 float(2.222) 254} 255int(7) 256array(7) { 257 [0]=> 258 string(44) "11 < 12. 123 >22 2592222 != 1111. 0000 = 0000 260" 261 [1]=> 262 string(5) "hello" 263 [2]=> 264 string(5) "world" 265 ["f"]=> 266 string(5) "first" 267 ["s"]=> 268 string(6) "second" 269 [3]=> 270 int(1) 271 [4]=> 272 float(2.222) 273} 274-- Iteration 6 -- 275int(5) 276array(5) { 277 [0]=> 278 string(123) "This's a string with quotes: 279"strings in double quote"; 280'strings in single quote'; 281this\line is single quoted /with\slashes" 282 ["f"]=> 283 string(5) "first" 284 ["s"]=> 285 string(6) "second" 286 [1]=> 287 int(1) 288 [2]=> 289 float(2.222) 290} 291int(7) 292array(7) { 293 [0]=> 294 string(123) "This's a string with quotes: 295"strings in double quote"; 296'strings in single quote'; 297this\line is single quoted /with\slashes" 298 [1]=> 299 string(5) "hello" 300 [2]=> 301 string(5) "world" 302 ["f"]=> 303 string(5) "first" 304 ["s"]=> 305 string(6) "second" 306 [3]=> 307 int(1) 308 [4]=> 309 float(2.222) 310} 311Done 312