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