1--TEST-- 2Test array_reverse() function : usage variations - different array values for 'array' argument 3--FILE-- 4<?php 5/* 6 * Testing the functionality of array_reverse() by giving 7 * different array values for $array argument 8*/ 9 10echo "*** Testing array_reverse() : usage variations ***\n"; 11 12//get an unset variable 13$unset_var = 10; 14unset ($unset_var); 15 16//get a resource variable 17$fp = fopen(__FILE__, "r"); 18 19//get a class 20class classA 21{ 22 public function __toString(){ 23 return "Class A object"; 24 } 25} 26 27// get a heredoc string 28$heredoc = <<<EOT 29Hello world 30EOT; 31 32$arrays = array ( 33/*1*/ array(1, 2), // array with default keys and numeric values 34 array(1.1, 2.2), // array with default keys & float values 35 array( array(2), array(1)), // sub arrays 36 array(false,true), // array with default keys and boolean values 37 array(), // empty array 38 array(NULL), // array with NULL 39 array("a","aaaa","b","bbbb","c","ccccc"), 40 41 // associative arrays 42/*8*/ array(1 => "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values 43 array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values 44 array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values 45 array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value 46 array("one" => 1, 2 => "two", 4 => "four"), //mixed 47 48 // associative array, containing null/empty/boolean values as key/value 49/*13*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), 50 array(true => "true", false => "false", "false" => false, "true" => true), 51 array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), 52 array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), 53 array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), 54 55 // array with repetitive keys 56/*18*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3) 57); 58 59// loop through the various elements of $arrays to test array_reverse() 60$iterator = 1; 61foreach($arrays as $array) { 62 echo "-- Iteration $iterator --\n"; 63 // with default argument 64 echo "- with default argument -\n"; 65 var_dump( array_reverse($array) ); 66 // with all possible arguments 67 echo "- with \$preserve keys = true -\n"; 68 var_dump( array_reverse($array, true) ); 69 echo "- with \$preserve_keys = false -\n"; 70 var_dump( array_reverse($array, false) ); 71 $iterator++; 72}; 73 74// close the file resource used 75fclose($fp); 76 77echo "Done"; 78?> 79--EXPECT-- 80*** Testing array_reverse() : usage variations *** 81-- Iteration 1 -- 82- with default argument - 83array(2) { 84 [0]=> 85 int(2) 86 [1]=> 87 int(1) 88} 89- with $preserve keys = true - 90array(2) { 91 [1]=> 92 int(2) 93 [0]=> 94 int(1) 95} 96- with $preserve_keys = false - 97array(2) { 98 [0]=> 99 int(2) 100 [1]=> 101 int(1) 102} 103-- Iteration 2 -- 104- with default argument - 105array(2) { 106 [0]=> 107 float(2.2) 108 [1]=> 109 float(1.1) 110} 111- with $preserve keys = true - 112array(2) { 113 [1]=> 114 float(2.2) 115 [0]=> 116 float(1.1) 117} 118- with $preserve_keys = false - 119array(2) { 120 [0]=> 121 float(2.2) 122 [1]=> 123 float(1.1) 124} 125-- Iteration 3 -- 126- with default argument - 127array(2) { 128 [0]=> 129 array(1) { 130 [0]=> 131 int(1) 132 } 133 [1]=> 134 array(1) { 135 [0]=> 136 int(2) 137 } 138} 139- with $preserve keys = true - 140array(2) { 141 [1]=> 142 array(1) { 143 [0]=> 144 int(1) 145 } 146 [0]=> 147 array(1) { 148 [0]=> 149 int(2) 150 } 151} 152- with $preserve_keys = false - 153array(2) { 154 [0]=> 155 array(1) { 156 [0]=> 157 int(1) 158 } 159 [1]=> 160 array(1) { 161 [0]=> 162 int(2) 163 } 164} 165-- Iteration 4 -- 166- with default argument - 167array(2) { 168 [0]=> 169 bool(true) 170 [1]=> 171 bool(false) 172} 173- with $preserve keys = true - 174array(2) { 175 [1]=> 176 bool(true) 177 [0]=> 178 bool(false) 179} 180- with $preserve_keys = false - 181array(2) { 182 [0]=> 183 bool(true) 184 [1]=> 185 bool(false) 186} 187-- Iteration 5 -- 188- with default argument - 189array(0) { 190} 191- with $preserve keys = true - 192array(0) { 193} 194- with $preserve_keys = false - 195array(0) { 196} 197-- Iteration 6 -- 198- with default argument - 199array(1) { 200 [0]=> 201 NULL 202} 203- with $preserve keys = true - 204array(1) { 205 [0]=> 206 NULL 207} 208- with $preserve_keys = false - 209array(1) { 210 [0]=> 211 NULL 212} 213-- Iteration 7 -- 214- with default argument - 215array(6) { 216 [0]=> 217 string(5) "ccccc" 218 [1]=> 219 string(1) "c" 220 [2]=> 221 string(4) "bbbb" 222 [3]=> 223 string(1) "b" 224 [4]=> 225 string(4) "aaaa" 226 [5]=> 227 string(1) "a" 228} 229- with $preserve keys = true - 230array(6) { 231 [5]=> 232 string(5) "ccccc" 233 [4]=> 234 string(1) "c" 235 [3]=> 236 string(4) "bbbb" 237 [2]=> 238 string(1) "b" 239 [1]=> 240 string(4) "aaaa" 241 [0]=> 242 string(1) "a" 243} 244- with $preserve_keys = false - 245array(6) { 246 [0]=> 247 string(5) "ccccc" 248 [1]=> 249 string(1) "c" 250 [2]=> 251 string(4) "bbbb" 252 [3]=> 253 string(1) "b" 254 [4]=> 255 string(4) "aaaa" 256 [5]=> 257 string(1) "a" 258} 259-- Iteration 8 -- 260- with default argument - 261array(3) { 262 [0]=> 263 string(5) "three" 264 [1]=> 265 string(3) "two" 266 [2]=> 267 string(3) "one" 268} 269- with $preserve keys = true - 270array(3) { 271 [3]=> 272 string(5) "three" 273 [2]=> 274 string(3) "two" 275 [1]=> 276 string(3) "one" 277} 278- with $preserve_keys = false - 279array(3) { 280 [0]=> 281 string(5) "three" 282 [1]=> 283 string(3) "two" 284 [2]=> 285 string(3) "one" 286} 287-- Iteration 9 -- 288- with default argument - 289array(3) { 290 ["three"]=> 291 int(3) 292 ["two"]=> 293 int(2) 294 ["one"]=> 295 int(1) 296} 297- with $preserve keys = true - 298array(3) { 299 ["three"]=> 300 int(3) 301 ["two"]=> 302 int(2) 303 ["one"]=> 304 int(1) 305} 306- with $preserve_keys = false - 307array(3) { 308 ["three"]=> 309 int(3) 310 ["two"]=> 311 int(2) 312 ["one"]=> 313 int(1) 314} 315-- Iteration 10 -- 316- with default argument - 317array(4) { 318 [0]=> 319 int(30) 320 [1]=> 321 int(40) 322 [2]=> 323 int(20) 324 [3]=> 325 int(10) 326} 327- with $preserve keys = true - 328array(4) { 329 [3]=> 330 int(30) 331 [4]=> 332 int(40) 333 [2]=> 334 int(20) 335 [1]=> 336 int(10) 337} 338- with $preserve_keys = false - 339array(4) { 340 [0]=> 341 int(30) 342 [1]=> 343 int(40) 344 [2]=> 345 int(20) 346 [3]=> 347 int(10) 348} 349-- Iteration 11 -- 350- with default argument - 351array(3) { 352 ["three"]=> 353 string(6) "thirty" 354 ["two"]=> 355 string(6) "twenty" 356 ["one"]=> 357 string(3) "ten" 358} 359- with $preserve keys = true - 360array(3) { 361 ["three"]=> 362 string(6) "thirty" 363 ["two"]=> 364 string(6) "twenty" 365 ["one"]=> 366 string(3) "ten" 367} 368- with $preserve_keys = false - 369array(3) { 370 ["three"]=> 371 string(6) "thirty" 372 ["two"]=> 373 string(6) "twenty" 374 ["one"]=> 375 string(3) "ten" 376} 377-- Iteration 12 -- 378- with default argument - 379array(3) { 380 [0]=> 381 string(4) "four" 382 [1]=> 383 string(3) "two" 384 ["one"]=> 385 int(1) 386} 387- with $preserve keys = true - 388array(3) { 389 [4]=> 390 string(4) "four" 391 [2]=> 392 string(3) "two" 393 ["one"]=> 394 int(1) 395} 396- with $preserve_keys = false - 397array(3) { 398 [0]=> 399 string(4) "four" 400 [1]=> 401 string(3) "two" 402 ["one"]=> 403 int(1) 404} 405-- Iteration 13 -- 406- with default argument - 407array(3) { 408 ["null"]=> 409 NULL 410 ["NULL"]=> 411 NULL 412 [""]=> 413 string(4) "null" 414} 415- with $preserve keys = true - 416array(3) { 417 ["null"]=> 418 NULL 419 ["NULL"]=> 420 NULL 421 [""]=> 422 string(4) "null" 423} 424- with $preserve_keys = false - 425array(3) { 426 ["null"]=> 427 NULL 428 ["NULL"]=> 429 NULL 430 [""]=> 431 string(4) "null" 432} 433-- Iteration 14 -- 434- with default argument - 435array(4) { 436 ["true"]=> 437 bool(true) 438 ["false"]=> 439 bool(false) 440 [0]=> 441 string(5) "false" 442 [1]=> 443 string(4) "true" 444} 445- with $preserve keys = true - 446array(4) { 447 ["true"]=> 448 bool(true) 449 ["false"]=> 450 bool(false) 451 [0]=> 452 string(5) "false" 453 [1]=> 454 string(4) "true" 455} 456- with $preserve_keys = false - 457array(4) { 458 ["true"]=> 459 bool(true) 460 ["false"]=> 461 bool(false) 462 [0]=> 463 string(5) "false" 464 [1]=> 465 string(4) "true" 466} 467-- Iteration 15 -- 468- with default argument - 469array(3) { 470 ["emptys"]=> 471 string(0) "" 472 ["emptyd"]=> 473 string(0) "" 474 [""]=> 475 string(6) "emptys" 476} 477- with $preserve keys = true - 478array(3) { 479 ["emptys"]=> 480 string(0) "" 481 ["emptyd"]=> 482 string(0) "" 483 [""]=> 484 string(6) "emptys" 485} 486- with $preserve_keys = false - 487array(3) { 488 ["emptys"]=> 489 string(0) "" 490 ["emptyd"]=> 491 string(0) "" 492 [""]=> 493 string(6) "emptys" 494} 495-- Iteration 16 -- 496- with default argument - 497array(6) { 498 [0]=> 499 bool(true) 500 [1]=> 501 bool(false) 502 [2]=> 503 NULL 504 [3]=> 505 NULL 506 [4]=> 507 string(0) "" 508 [5]=> 509 string(0) "" 510} 511- with $preserve keys = true - 512array(6) { 513 [6]=> 514 bool(true) 515 [5]=> 516 bool(false) 517 [4]=> 518 NULL 519 [3]=> 520 NULL 521 [2]=> 522 string(0) "" 523 [1]=> 524 string(0) "" 525} 526- with $preserve_keys = false - 527array(6) { 528 [0]=> 529 bool(true) 530 [1]=> 531 bool(false) 532 [2]=> 533 NULL 534 [3]=> 535 NULL 536 [4]=> 537 string(0) "" 538 [5]=> 539 string(0) "" 540} 541-- Iteration 17 -- 542- with default argument - 543array(3) { 544 [0]=> 545 int(6) 546 [1]=> 547 int(5) 548 [""]=> 549 int(4) 550} 551- with $preserve keys = true - 552array(3) { 553 [1]=> 554 int(6) 555 [0]=> 556 int(5) 557 [""]=> 558 int(4) 559} 560- with $preserve_keys = false - 561array(3) { 562 [0]=> 563 int(6) 564 [1]=> 565 int(5) 566 [""]=> 567 int(4) 568} 569-- Iteration 18 -- 570- with default argument - 571array(3) { 572 ["three"]=> 573 int(3) 574 ["two"]=> 575 int(20) 576 ["One"]=> 577 int(10) 578} 579- with $preserve keys = true - 580array(3) { 581 ["three"]=> 582 int(3) 583 ["two"]=> 584 int(20) 585 ["One"]=> 586 int(10) 587} 588- with $preserve_keys = false - 589array(3) { 590 ["three"]=> 591 int(3) 592 ["two"]=> 593 int(20) 594 ["One"]=> 595 int(10) 596} 597Done 598