1--TEST-- 2Test array_pad() function : usage variations - possible values for 'pad_value' argument 3--FILE-- 4<?php 5/* 6* Testing array_pad() function for expected behavior by passing 7* different possible values for $pad_value argument. 8* $input and $pad_size arguments take fixed value. 9*/ 10 11echo "*** Testing array_pad() : possible values for \$pad_value argument ***\n"; 12 13// Initialise $input and $pad_size argument 14$input = array(1, 2); 15$pad_size = 4; 16 17//get an unset variable 18$unset_var = 10; 19unset ($unset_var); 20 21// get a class 22class classA 23{ 24 public function __toString() { 25 return "Class A object"; 26 } 27} 28 29// heredoc string 30$heredoc = <<<EOT 31hello world 32EOT; 33 34// get a resource variable 35$fp = fopen(__FILE__, "r"); 36 37// get a reference variable 38$value = "hello"; 39$reference = &$value; 40 41// different values to be passed to $pad_value argument 42$pad_values = array( 43 44 // int data 45/*1*/ 0, 46 1, 47 12345, 48 -2345, 49 50 // float data 51/*5*/ 10.5, 52 -10.5, 53 12.3456789000e10, 54 12.3456789000E-10, 55 .5, 56 57 // array data 58/*10*/ array(), 59 array(0), 60 array(1), 61 array(1, 2), 62 array('color' => 'red', 'item' => 'pen'), 63 64 // null data 65/*15*/ NULL, 66 null, 67 68 // boolean data 69/*17*/ true, 70 false, 71 TRUE, 72 FALSE, 73 74 // empty data 75/*21*/ "", 76 '', 77 78 // string data 79/*23*/ "string", 80 'string', 81 $heredoc, 82 83 // strings with different white spaces 84/*26*/ "\v\fHello\t world!! \rstring\n", 85 '\v\fHello\t world!! \rstring\n', 86 87 // object data 88/*28*/ new classA(), 89 90 // undefined data 91/*29*/ @$undefined_var, 92 93 // unset data 94/*30*/ @$unset_var, 95 96 // resource variable 97/*31*/ $fp, 98 99 // reference variable 100/*32*/ $reference 101); 102 103// loop through each element of $pad_values to check the behavior of array_pad() 104$iterator = 1; 105foreach($pad_values as $pad_value) { 106 echo "-- Iteration $iterator --\n"; 107 var_dump( array_pad($input, $pad_size, $pad_value) ); // positive 'pad_size' 108 var_dump( array_pad($input, -$pad_size, $pad_value) ); // negative 'pad_size' 109 $iterator++; 110}; 111 112echo "Done"; 113?> 114--EXPECTF-- 115*** Testing array_pad() : possible values for $pad_value argument *** 116-- Iteration 1 -- 117array(4) { 118 [0]=> 119 int(1) 120 [1]=> 121 int(2) 122 [2]=> 123 int(0) 124 [3]=> 125 int(0) 126} 127array(4) { 128 [0]=> 129 int(0) 130 [1]=> 131 int(0) 132 [2]=> 133 int(1) 134 [3]=> 135 int(2) 136} 137-- Iteration 2 -- 138array(4) { 139 [0]=> 140 int(1) 141 [1]=> 142 int(2) 143 [2]=> 144 int(1) 145 [3]=> 146 int(1) 147} 148array(4) { 149 [0]=> 150 int(1) 151 [1]=> 152 int(1) 153 [2]=> 154 int(1) 155 [3]=> 156 int(2) 157} 158-- Iteration 3 -- 159array(4) { 160 [0]=> 161 int(1) 162 [1]=> 163 int(2) 164 [2]=> 165 int(12345) 166 [3]=> 167 int(12345) 168} 169array(4) { 170 [0]=> 171 int(12345) 172 [1]=> 173 int(12345) 174 [2]=> 175 int(1) 176 [3]=> 177 int(2) 178} 179-- Iteration 4 -- 180array(4) { 181 [0]=> 182 int(1) 183 [1]=> 184 int(2) 185 [2]=> 186 int(-2345) 187 [3]=> 188 int(-2345) 189} 190array(4) { 191 [0]=> 192 int(-2345) 193 [1]=> 194 int(-2345) 195 [2]=> 196 int(1) 197 [3]=> 198 int(2) 199} 200-- Iteration 5 -- 201array(4) { 202 [0]=> 203 int(1) 204 [1]=> 205 int(2) 206 [2]=> 207 float(10.5) 208 [3]=> 209 float(10.5) 210} 211array(4) { 212 [0]=> 213 float(10.5) 214 [1]=> 215 float(10.5) 216 [2]=> 217 int(1) 218 [3]=> 219 int(2) 220} 221-- Iteration 6 -- 222array(4) { 223 [0]=> 224 int(1) 225 [1]=> 226 int(2) 227 [2]=> 228 float(-10.5) 229 [3]=> 230 float(-10.5) 231} 232array(4) { 233 [0]=> 234 float(-10.5) 235 [1]=> 236 float(-10.5) 237 [2]=> 238 int(1) 239 [3]=> 240 int(2) 241} 242-- Iteration 7 -- 243array(4) { 244 [0]=> 245 int(1) 246 [1]=> 247 int(2) 248 [2]=> 249 float(123456789000) 250 [3]=> 251 float(123456789000) 252} 253array(4) { 254 [0]=> 255 float(123456789000) 256 [1]=> 257 float(123456789000) 258 [2]=> 259 int(1) 260 [3]=> 261 int(2) 262} 263-- Iteration 8 -- 264array(4) { 265 [0]=> 266 int(1) 267 [1]=> 268 int(2) 269 [2]=> 270 float(1.23456789E-9) 271 [3]=> 272 float(1.23456789E-9) 273} 274array(4) { 275 [0]=> 276 float(1.23456789E-9) 277 [1]=> 278 float(1.23456789E-9) 279 [2]=> 280 int(1) 281 [3]=> 282 int(2) 283} 284-- Iteration 9 -- 285array(4) { 286 [0]=> 287 int(1) 288 [1]=> 289 int(2) 290 [2]=> 291 float(0.5) 292 [3]=> 293 float(0.5) 294} 295array(4) { 296 [0]=> 297 float(0.5) 298 [1]=> 299 float(0.5) 300 [2]=> 301 int(1) 302 [3]=> 303 int(2) 304} 305-- Iteration 10 -- 306array(4) { 307 [0]=> 308 int(1) 309 [1]=> 310 int(2) 311 [2]=> 312 array(0) { 313 } 314 [3]=> 315 array(0) { 316 } 317} 318array(4) { 319 [0]=> 320 array(0) { 321 } 322 [1]=> 323 array(0) { 324 } 325 [2]=> 326 int(1) 327 [3]=> 328 int(2) 329} 330-- Iteration 11 -- 331array(4) { 332 [0]=> 333 int(1) 334 [1]=> 335 int(2) 336 [2]=> 337 array(1) { 338 [0]=> 339 int(0) 340 } 341 [3]=> 342 array(1) { 343 [0]=> 344 int(0) 345 } 346} 347array(4) { 348 [0]=> 349 array(1) { 350 [0]=> 351 int(0) 352 } 353 [1]=> 354 array(1) { 355 [0]=> 356 int(0) 357 } 358 [2]=> 359 int(1) 360 [3]=> 361 int(2) 362} 363-- Iteration 12 -- 364array(4) { 365 [0]=> 366 int(1) 367 [1]=> 368 int(2) 369 [2]=> 370 array(1) { 371 [0]=> 372 int(1) 373 } 374 [3]=> 375 array(1) { 376 [0]=> 377 int(1) 378 } 379} 380array(4) { 381 [0]=> 382 array(1) { 383 [0]=> 384 int(1) 385 } 386 [1]=> 387 array(1) { 388 [0]=> 389 int(1) 390 } 391 [2]=> 392 int(1) 393 [3]=> 394 int(2) 395} 396-- Iteration 13 -- 397array(4) { 398 [0]=> 399 int(1) 400 [1]=> 401 int(2) 402 [2]=> 403 array(2) { 404 [0]=> 405 int(1) 406 [1]=> 407 int(2) 408 } 409 [3]=> 410 array(2) { 411 [0]=> 412 int(1) 413 [1]=> 414 int(2) 415 } 416} 417array(4) { 418 [0]=> 419 array(2) { 420 [0]=> 421 int(1) 422 [1]=> 423 int(2) 424 } 425 [1]=> 426 array(2) { 427 [0]=> 428 int(1) 429 [1]=> 430 int(2) 431 } 432 [2]=> 433 int(1) 434 [3]=> 435 int(2) 436} 437-- Iteration 14 -- 438array(4) { 439 [0]=> 440 int(1) 441 [1]=> 442 int(2) 443 [2]=> 444 array(2) { 445 ["color"]=> 446 string(3) "red" 447 ["item"]=> 448 string(3) "pen" 449 } 450 [3]=> 451 array(2) { 452 ["color"]=> 453 string(3) "red" 454 ["item"]=> 455 string(3) "pen" 456 } 457} 458array(4) { 459 [0]=> 460 array(2) { 461 ["color"]=> 462 string(3) "red" 463 ["item"]=> 464 string(3) "pen" 465 } 466 [1]=> 467 array(2) { 468 ["color"]=> 469 string(3) "red" 470 ["item"]=> 471 string(3) "pen" 472 } 473 [2]=> 474 int(1) 475 [3]=> 476 int(2) 477} 478-- Iteration 15 -- 479array(4) { 480 [0]=> 481 int(1) 482 [1]=> 483 int(2) 484 [2]=> 485 NULL 486 [3]=> 487 NULL 488} 489array(4) { 490 [0]=> 491 NULL 492 [1]=> 493 NULL 494 [2]=> 495 int(1) 496 [3]=> 497 int(2) 498} 499-- Iteration 16 -- 500array(4) { 501 [0]=> 502 int(1) 503 [1]=> 504 int(2) 505 [2]=> 506 NULL 507 [3]=> 508 NULL 509} 510array(4) { 511 [0]=> 512 NULL 513 [1]=> 514 NULL 515 [2]=> 516 int(1) 517 [3]=> 518 int(2) 519} 520-- Iteration 17 -- 521array(4) { 522 [0]=> 523 int(1) 524 [1]=> 525 int(2) 526 [2]=> 527 bool(true) 528 [3]=> 529 bool(true) 530} 531array(4) { 532 [0]=> 533 bool(true) 534 [1]=> 535 bool(true) 536 [2]=> 537 int(1) 538 [3]=> 539 int(2) 540} 541-- Iteration 18 -- 542array(4) { 543 [0]=> 544 int(1) 545 [1]=> 546 int(2) 547 [2]=> 548 bool(false) 549 [3]=> 550 bool(false) 551} 552array(4) { 553 [0]=> 554 bool(false) 555 [1]=> 556 bool(false) 557 [2]=> 558 int(1) 559 [3]=> 560 int(2) 561} 562-- Iteration 19 -- 563array(4) { 564 [0]=> 565 int(1) 566 [1]=> 567 int(2) 568 [2]=> 569 bool(true) 570 [3]=> 571 bool(true) 572} 573array(4) { 574 [0]=> 575 bool(true) 576 [1]=> 577 bool(true) 578 [2]=> 579 int(1) 580 [3]=> 581 int(2) 582} 583-- Iteration 20 -- 584array(4) { 585 [0]=> 586 int(1) 587 [1]=> 588 int(2) 589 [2]=> 590 bool(false) 591 [3]=> 592 bool(false) 593} 594array(4) { 595 [0]=> 596 bool(false) 597 [1]=> 598 bool(false) 599 [2]=> 600 int(1) 601 [3]=> 602 int(2) 603} 604-- Iteration 21 -- 605array(4) { 606 [0]=> 607 int(1) 608 [1]=> 609 int(2) 610 [2]=> 611 string(0) "" 612 [3]=> 613 string(0) "" 614} 615array(4) { 616 [0]=> 617 string(0) "" 618 [1]=> 619 string(0) "" 620 [2]=> 621 int(1) 622 [3]=> 623 int(2) 624} 625-- Iteration 22 -- 626array(4) { 627 [0]=> 628 int(1) 629 [1]=> 630 int(2) 631 [2]=> 632 string(0) "" 633 [3]=> 634 string(0) "" 635} 636array(4) { 637 [0]=> 638 string(0) "" 639 [1]=> 640 string(0) "" 641 [2]=> 642 int(1) 643 [3]=> 644 int(2) 645} 646-- Iteration 23 -- 647array(4) { 648 [0]=> 649 int(1) 650 [1]=> 651 int(2) 652 [2]=> 653 string(6) "string" 654 [3]=> 655 string(6) "string" 656} 657array(4) { 658 [0]=> 659 string(6) "string" 660 [1]=> 661 string(6) "string" 662 [2]=> 663 int(1) 664 [3]=> 665 int(2) 666} 667-- Iteration 24 -- 668array(4) { 669 [0]=> 670 int(1) 671 [1]=> 672 int(2) 673 [2]=> 674 string(6) "string" 675 [3]=> 676 string(6) "string" 677} 678array(4) { 679 [0]=> 680 string(6) "string" 681 [1]=> 682 string(6) "string" 683 [2]=> 684 int(1) 685 [3]=> 686 int(2) 687} 688-- Iteration 25 -- 689array(4) { 690 [0]=> 691 int(1) 692 [1]=> 693 int(2) 694 [2]=> 695 string(11) "hello world" 696 [3]=> 697 string(11) "hello world" 698} 699array(4) { 700 [0]=> 701 string(11) "hello world" 702 [1]=> 703 string(11) "hello world" 704 [2]=> 705 int(1) 706 [3]=> 707 int(2) 708} 709-- Iteration 26 -- 710array(4) { 711 [0]=> 712 int(1) 713 [1]=> 714 int(2) 715 [2]=> 716 string(25) "Hello world!! 716string 717" 718 [3]=> 719 string(25) "Hello world!! 719string 720" 721} 722array(4) { 723 [0]=> 724 string(25) "Hello world!! 724string 725" 726 [1]=> 727 string(25) "Hello world!! 727string 728" 729 [2]=> 730 int(1) 731 [3]=> 732 int(2) 733} 734-- Iteration 27 -- 735array(4) { 736 [0]=> 737 int(1) 738 [1]=> 739 int(2) 740 [2]=> 741 string(30) "\v\fHello\t world!! \rstring\n" 742 [3]=> 743 string(30) "\v\fHello\t world!! \rstring\n" 744} 745array(4) { 746 [0]=> 747 string(30) "\v\fHello\t world!! \rstring\n" 748 [1]=> 749 string(30) "\v\fHello\t world!! \rstring\n" 750 [2]=> 751 int(1) 752 [3]=> 753 int(2) 754} 755-- Iteration 28 -- 756array(4) { 757 [0]=> 758 int(1) 759 [1]=> 760 int(2) 761 [2]=> 762 object(classA)#%d (0) { 763 } 764 [3]=> 765 object(classA)#%d (0) { 766 } 767} 768array(4) { 769 [0]=> 770 object(classA)#%d (0) { 771 } 772 [1]=> 773 object(classA)#%d (0) { 774 } 775 [2]=> 776 int(1) 777 [3]=> 778 int(2) 779} 780-- Iteration 29 -- 781array(4) { 782 [0]=> 783 int(1) 784 [1]=> 785 int(2) 786 [2]=> 787 NULL 788 [3]=> 789 NULL 790} 791array(4) { 792 [0]=> 793 NULL 794 [1]=> 795 NULL 796 [2]=> 797 int(1) 798 [3]=> 799 int(2) 800} 801-- Iteration 30 -- 802array(4) { 803 [0]=> 804 int(1) 805 [1]=> 806 int(2) 807 [2]=> 808 NULL 809 [3]=> 810 NULL 811} 812array(4) { 813 [0]=> 814 NULL 815 [1]=> 816 NULL 817 [2]=> 818 int(1) 819 [3]=> 820 int(2) 821} 822-- Iteration 31 -- 823array(4) { 824 [0]=> 825 int(1) 826 [1]=> 827 int(2) 828 [2]=> 829 resource(%d) of type (stream) 830 [3]=> 831 resource(%d) of type (stream) 832} 833array(4) { 834 [0]=> 835 resource(%d) of type (stream) 836 [1]=> 837 resource(%d) of type (stream) 838 [2]=> 839 int(1) 840 [3]=> 841 int(2) 842} 843-- Iteration 32 -- 844array(4) { 845 [0]=> 846 int(1) 847 [1]=> 848 int(2) 849 [2]=> 850 string(5) "hello" 851 [3]=> 852 string(5) "hello" 853} 854array(4) { 855 [0]=> 856 string(5) "hello" 857 [1]=> 858 string(5) "hello" 859 [2]=> 860 int(1) 861 [3]=> 862 int(2) 863} 864Done 865