1--TEST-- 2Test array_pad() function : usage variations - different arrays for 'input' argument 3--FILE-- 4<?php 5/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) 6 * Description: Returns a copy of input array padded with pad_value to size pad_size 7 * Source code: ext/standard/array.c 8*/ 9 10/* 11* Passing different arrays to $input argument and testing whether 12* array_pad() behaves in an expected way with the other arguments passed to the function. 13* The $pad_size and $pad_value arguments passed are fixed values. 14*/ 15 16echo "*** Testing array_pad() : Passing different arrays to \$input argument ***\n"; 17 18/* Different heredoc strings */ 19 20// heredoc with blank line 21$blank_line = <<<EOT 22 23 24EOT; 25 26// heredoc with multiline string 27$multiline_string = <<<EOT 28hello world 29The big brown fox jumped over; 30the lazy dog 31This is a double quoted string 32EOT; 33 34// heredoc with different whitespaces 35$diff_whitespaces = <<<EOT 36hello\r world\t 371111\t\t != 2222\v\v 38heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces 39EOT; 40 41// heredoc with quoted strings and numeric values 42$numeric_string = <<<EOT 4311 < 12. 123 >22 44'single quoted string' 45"double quoted string" 462222 != 1111.\t 0000 = 0000\n 47EOT; 48 49// different arrays to be passed to $input argument 50$inputs = array ( 51/*1*/ array(1, 2), // with default keys and numeric values 52 array(1.1, 2.2), // with default keys & float values 53 array(false,true), // with default keys and boolean values 54 array(), // empty array 55/*5*/ array(NULL), // with NULL 56 array("a\v\f", "aaaa\r", "b\tbbb", "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // with double quoted strings 57 array('a\v\f', 'aaaa\r', 'b\tbbb', '\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // with single quoted strings 58 array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $numeric_string), // with heredocs 59 60 // associative arrays 61/*9*/ array(1 => "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values 62 array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values 63 array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values 64 array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value 65 array("one" => 1, 2 => "two", 4 => "four"), //mixed 66 67 // associative array, containing null/empty/boolean values as key/value 68/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), 69 array(true => "true", false => "false", "false" => false, "true" => true), 70 array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), 71 array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), 72 array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), 73 74 // array with repetative keys 75/*19*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3) 76); 77 78// initialize the $pad_size and $pad_value arguments 79$pad_size = 6; 80$pad_value = "HELLO"; 81 82// loop through each sub-array within $inputs to check the behavior of array_pad() 83$iterator = 1; 84foreach($inputs as $input) { 85 echo "-- Iteration $iterator --\n"; 86 var_dump( array_pad($input, $pad_size, $pad_value) ); // positive 'pad_size' 87 var_dump( array_pad($input, -$pad_size, $pad_value) ); // negative 'pad_size' 88 $iterator++; 89}; 90 91echo "Done"; 92?> 93--EXPECTF-- 94*** Testing array_pad() : Passing different arrays to $input argument *** 95-- Iteration 1 -- 96array(6) { 97 [0]=> 98 int(1) 99 [1]=> 100 int(2) 101 [2]=> 102 string(5) "HELLO" 103 [3]=> 104 string(5) "HELLO" 105 [4]=> 106 string(5) "HELLO" 107 [5]=> 108 string(5) "HELLO" 109} 110array(6) { 111 [0]=> 112 string(5) "HELLO" 113 [1]=> 114 string(5) "HELLO" 115 [2]=> 116 string(5) "HELLO" 117 [3]=> 118 string(5) "HELLO" 119 [4]=> 120 int(1) 121 [5]=> 122 int(2) 123} 124-- Iteration 2 -- 125array(6) { 126 [0]=> 127 float(1.1) 128 [1]=> 129 float(2.2) 130 [2]=> 131 string(5) "HELLO" 132 [3]=> 133 string(5) "HELLO" 134 [4]=> 135 string(5) "HELLO" 136 [5]=> 137 string(5) "HELLO" 138} 139array(6) { 140 [0]=> 141 string(5) "HELLO" 142 [1]=> 143 string(5) "HELLO" 144 [2]=> 145 string(5) "HELLO" 146 [3]=> 147 string(5) "HELLO" 148 [4]=> 149 float(1.1) 150 [5]=> 151 float(2.2) 152} 153-- Iteration 3 -- 154array(6) { 155 [0]=> 156 bool(false) 157 [1]=> 158 bool(true) 159 [2]=> 160 string(5) "HELLO" 161 [3]=> 162 string(5) "HELLO" 163 [4]=> 164 string(5) "HELLO" 165 [5]=> 166 string(5) "HELLO" 167} 168array(6) { 169 [0]=> 170 string(5) "HELLO" 171 [1]=> 172 string(5) "HELLO" 173 [2]=> 174 string(5) "HELLO" 175 [3]=> 176 string(5) "HELLO" 177 [4]=> 178 bool(false) 179 [5]=> 180 bool(true) 181} 182-- Iteration 4 -- 183array(6) { 184 [0]=> 185 string(5) "HELLO" 186 [1]=> 187 string(5) "HELLO" 188 [2]=> 189 string(5) "HELLO" 190 [3]=> 191 string(5) "HELLO" 192 [4]=> 193 string(5) "HELLO" 194 [5]=> 195 string(5) "HELLO" 196} 197array(6) { 198 [0]=> 199 string(5) "HELLO" 200 [1]=> 201 string(5) "HELLO" 202 [2]=> 203 string(5) "HELLO" 204 [3]=> 205 string(5) "HELLO" 206 [4]=> 207 string(5) "HELLO" 208 [5]=> 209 string(5) "HELLO" 210} 211-- Iteration 5 -- 212array(6) { 213 [0]=> 214 NULL 215 [1]=> 216 string(5) "HELLO" 217 [2]=> 218 string(5) "HELLO" 219 [3]=> 220 string(5) "HELLO" 221 [4]=> 222 string(5) "HELLO" 223 [5]=> 224 string(5) "HELLO" 225} 226array(6) { 227 [0]=> 228 string(5) "HELLO" 229 [1]=> 230 string(5) "HELLO" 231 [2]=> 232 string(5) "HELLO" 233 [3]=> 234 string(5) "HELLO" 235 [4]=> 236 string(5) "HELLO" 237 [5]=> 238 NULL 239} 240-- Iteration 6 -- 241array(6) { 242 [0]=> 243 string(3) "a" 244 [1]=> 245 string(5) "aaaa 245" 246 [2]=> 247 string(5) "b bbb" 248 [3]=> 249 string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}" 250 [4]=> 251 string(5) "HELLO" 252 [5]=> 253 string(5) "HELLO" 254} 255array(6) { 256 [0]=> 257 string(5) "HELLO" 258 [1]=> 259 string(5) "HELLO" 260 [2]=> 261 string(3) "a" 262 [3]=> 263 string(5) "aaaa 263" 264 [4]=> 265 string(5) "b bbb" 266 [5]=> 267 string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}" 268} 269-- Iteration 7 -- 270array(6) { 271 [0]=> 272 string(5) "a\v\f" 273 [1]=> 274 string(6) "aaaa\r" 275 [2]=> 276 string(6) "b\tbbb" 277 [3]=> 278 string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}" 279 [4]=> 280 string(5) "HELLO" 281 [5]=> 282 string(5) "HELLO" 283} 284array(6) { 285 [0]=> 286 string(5) "HELLO" 287 [1]=> 288 string(5) "HELLO" 289 [2]=> 290 string(5) "a\v\f" 291 [3]=> 292 string(6) "aaaa\r" 293 [4]=> 294 string(6) "b\tbbb" 295 [5]=> 296 string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}" 297} 298-- Iteration 8 -- 299array(6) { 300 ["h1"]=> 301 string(1) " 302" 303 ["h2"]=> 304 string(86) "hello world 305The big brown fox jumped over; 306the lazy dog 307This is a double quoted string" 308 ["h3"]=> 309 string(88) "hello 309 world 3101111 != 2222 311heredoc 312double quoted string. withdifferentwhitespaces" 313 [0]=> 314 string(90) "11 < 12. 123 >22 315'single quoted string' 316"double quoted string" 3172222 != 1111. 0000 = 0000 318" 319 [1]=> 320 string(5) "HELLO" 321 [2]=> 322 string(5) "HELLO" 323} 324array(6) { 325 [0]=> 326 string(5) "HELLO" 327 [1]=> 328 string(5) "HELLO" 329 ["h1"]=> 330 string(1) " 331" 332 ["h2"]=> 333 string(86) "hello world 334The big brown fox jumped over; 335the lazy dog 336This is a double quoted string" 337 ["h3"]=> 338 string(88) "hello 338 world 3391111 != 2222 340heredoc 341double quoted string. withdifferentwhitespaces" 342 [2]=> 343 string(90) "11 < 12. 123 >22 344'single quoted string' 345"double quoted string" 3462222 != 1111. 0000 = 0000 347" 348} 349-- Iteration 9 -- 350array(6) { 351 [0]=> 352 string(3) "one" 353 [1]=> 354 string(3) "two" 355 [2]=> 356 string(5) "three" 357 [3]=> 358 string(5) "HELLO" 359 [4]=> 360 string(5) "HELLO" 361 [5]=> 362 string(5) "HELLO" 363} 364array(6) { 365 [0]=> 366 string(5) "HELLO" 367 [1]=> 368 string(5) "HELLO" 369 [2]=> 370 string(5) "HELLO" 371 [3]=> 372 string(3) "one" 373 [4]=> 374 string(3) "two" 375 [5]=> 376 string(5) "three" 377} 378-- Iteration 10 -- 379array(6) { 380 ["one"]=> 381 int(1) 382 ["two"]=> 383 int(2) 384 ["three"]=> 385 int(3) 386 [0]=> 387 string(5) "HELLO" 388 [1]=> 389 string(5) "HELLO" 390 [2]=> 391 string(5) "HELLO" 392} 393array(6) { 394 [0]=> 395 string(5) "HELLO" 396 [1]=> 397 string(5) "HELLO" 398 [2]=> 399 string(5) "HELLO" 400 ["one"]=> 401 int(1) 402 ["two"]=> 403 int(2) 404 ["three"]=> 405 int(3) 406} 407-- Iteration 11 -- 408array(6) { 409 [0]=> 410 int(10) 411 [1]=> 412 int(20) 413 [2]=> 414 int(40) 415 [3]=> 416 int(30) 417 [4]=> 418 string(5) "HELLO" 419 [5]=> 420 string(5) "HELLO" 421} 422array(6) { 423 [0]=> 424 string(5) "HELLO" 425 [1]=> 426 string(5) "HELLO" 427 [2]=> 428 int(10) 429 [3]=> 430 int(20) 431 [4]=> 432 int(40) 433 [5]=> 434 int(30) 435} 436-- Iteration 12 -- 437array(6) { 438 ["one"]=> 439 string(3) "ten" 440 ["two"]=> 441 string(6) "twenty" 442 ["three"]=> 443 string(6) "thirty" 444 [0]=> 445 string(5) "HELLO" 446 [1]=> 447 string(5) "HELLO" 448 [2]=> 449 string(5) "HELLO" 450} 451array(6) { 452 [0]=> 453 string(5) "HELLO" 454 [1]=> 455 string(5) "HELLO" 456 [2]=> 457 string(5) "HELLO" 458 ["one"]=> 459 string(3) "ten" 460 ["two"]=> 461 string(6) "twenty" 462 ["three"]=> 463 string(6) "thirty" 464} 465-- Iteration 13 -- 466array(6) { 467 ["one"]=> 468 int(1) 469 [0]=> 470 string(3) "two" 471 [1]=> 472 string(4) "four" 473 [2]=> 474 string(5) "HELLO" 475 [3]=> 476 string(5) "HELLO" 477 [4]=> 478 string(5) "HELLO" 479} 480array(6) { 481 [0]=> 482 string(5) "HELLO" 483 [1]=> 484 string(5) "HELLO" 485 [2]=> 486 string(5) "HELLO" 487 ["one"]=> 488 int(1) 489 [3]=> 490 string(3) "two" 491 [4]=> 492 string(4) "four" 493} 494-- Iteration 14 -- 495array(6) { 496 [""]=> 497 string(4) "null" 498 ["NULL"]=> 499 NULL 500 ["null"]=> 501 NULL 502 [0]=> 503 string(5) "HELLO" 504 [1]=> 505 string(5) "HELLO" 506 [2]=> 507 string(5) "HELLO" 508} 509array(6) { 510 [0]=> 511 string(5) "HELLO" 512 [1]=> 513 string(5) "HELLO" 514 [2]=> 515 string(5) "HELLO" 516 [""]=> 517 string(4) "null" 518 ["NULL"]=> 519 NULL 520 ["null"]=> 521 NULL 522} 523-- Iteration 15 -- 524array(6) { 525 [0]=> 526 string(4) "true" 527 [1]=> 528 string(5) "false" 529 ["false"]=> 530 bool(false) 531 ["true"]=> 532 bool(true) 533 [2]=> 534 string(5) "HELLO" 535 [3]=> 536 string(5) "HELLO" 537} 538array(6) { 539 [0]=> 540 string(5) "HELLO" 541 [1]=> 542 string(5) "HELLO" 543 [2]=> 544 string(4) "true" 545 [3]=> 546 string(5) "false" 547 ["false"]=> 548 bool(false) 549 ["true"]=> 550 bool(true) 551} 552-- Iteration 16 -- 553array(6) { 554 [""]=> 555 string(6) "emptys" 556 ["emptyd"]=> 557 string(0) "" 558 ["emptys"]=> 559 string(0) "" 560 [0]=> 561 string(5) "HELLO" 562 [1]=> 563 string(5) "HELLO" 564 [2]=> 565 string(5) "HELLO" 566} 567array(6) { 568 [0]=> 569 string(5) "HELLO" 570 [1]=> 571 string(5) "HELLO" 572 [2]=> 573 string(5) "HELLO" 574 [""]=> 575 string(6) "emptys" 576 ["emptyd"]=> 577 string(0) "" 578 ["emptys"]=> 579 string(0) "" 580} 581-- Iteration 17 -- 582array(6) { 583 [1]=> 584 string(0) "" 585 [2]=> 586 string(0) "" 587 [3]=> 588 NULL 589 [4]=> 590 NULL 591 [5]=> 592 bool(false) 593 [6]=> 594 bool(true) 595} 596array(6) { 597 [1]=> 598 string(0) "" 599 [2]=> 600 string(0) "" 601 [3]=> 602 NULL 603 [4]=> 604 NULL 605 [5]=> 606 bool(false) 607 [6]=> 608 bool(true) 609} 610-- Iteration 18 -- 611array(6) { 612 [""]=> 613 int(4) 614 [0]=> 615 int(5) 616 [1]=> 617 int(6) 618 [2]=> 619 string(5) "HELLO" 620 [3]=> 621 string(5) "HELLO" 622 [4]=> 623 string(5) "HELLO" 624} 625array(6) { 626 [0]=> 627 string(5) "HELLO" 628 [1]=> 629 string(5) "HELLO" 630 [2]=> 631 string(5) "HELLO" 632 [""]=> 633 int(4) 634 [3]=> 635 int(5) 636 [4]=> 637 int(6) 638} 639-- Iteration 19 -- 640array(6) { 641 ["One"]=> 642 int(10) 643 ["two"]=> 644 int(20) 645 ["three"]=> 646 int(3) 647 [0]=> 648 string(5) "HELLO" 649 [1]=> 650 string(5) "HELLO" 651 [2]=> 652 string(5) "HELLO" 653} 654array(6) { 655 [0]=> 656 string(5) "HELLO" 657 [1]=> 658 string(5) "HELLO" 659 [2]=> 660 string(5) "HELLO" 661 ["One"]=> 662 int(10) 663 ["two"]=> 664 int(20) 665 ["three"]=> 666 int(3) 667} 668Done 669