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