array_splice_basic.phpt 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. --TEST--
  2. Test array_splice(): basic functionality
  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. echo "*** Testing array_splice() basic operations ***\n";
  10. echo "test truncation \n";
  11. $input = array("red", "green", "blue", "yellow");
  12. var_dump (array_splice($input, 2));
  13. var_dump ($input);
  14. // $input is now array("red", "green")
  15. echo "test removing entries from the middle \n";
  16. $input = array("red", "green", "blue", "yellow");
  17. var_dump (array_splice($input, 1, -1));
  18. var_dump ($input);
  19. // $input is now array("red", "yellow")
  20. echo "test substitution at end \n";
  21. $input = array("red", "green", "blue", "yellow");
  22. var_dump (array_splice($input, 1, count($input), "orange"));
  23. var_dump ($input);
  24. // $input is now array("red", "orange")
  25. $input = array("red", "green", "blue", "yellow");
  26. var_dump (array_splice($input, -1, 1, array("black", "maroon")));
  27. var_dump ($input);
  28. // $input is now array("red", "green",
  29. // "blue", "black", "maroon")
  30. echo "test insertion \n";
  31. $input = array("red", "green", "blue", "yellow");
  32. var_dump (array_splice($input, 3, 0, "purple"));
  33. var_dump ($input);
  34. // $input is now array("red", "green",
  35. // "blue", "purple", "yellow");
  36. ?>
  37. --EXPECT--
  38. *** Testing array_splice() basic operations ***
  39. test truncation
  40. array(2) {
  41. [0]=>
  42. string(4) "blue"
  43. [1]=>
  44. string(6) "yellow"
  45. }
  46. array(2) {
  47. [0]=>
  48. string(3) "red"
  49. [1]=>
  50. string(5) "green"
  51. }
  52. test removing entries from the middle
  53. array(2) {
  54. [0]=>
  55. string(5) "green"
  56. [1]=>
  57. string(4) "blue"
  58. }
  59. array(2) {
  60. [0]=>
  61. string(3) "red"
  62. [1]=>
  63. string(6) "yellow"
  64. }
  65. test substitution at end
  66. array(3) {
  67. [0]=>
  68. string(5) "green"
  69. [1]=>
  70. string(4) "blue"
  71. [2]=>
  72. string(6) "yellow"
  73. }
  74. array(2) {
  75. [0]=>
  76. string(3) "red"
  77. [1]=>
  78. string(6) "orange"
  79. }
  80. array(1) {
  81. [0]=>
  82. string(6) "yellow"
  83. }
  84. array(5) {
  85. [0]=>
  86. string(3) "red"
  87. [1]=>
  88. string(5) "green"
  89. [2]=>
  90. string(4) "blue"
  91. [3]=>
  92. string(5) "black"
  93. [4]=>
  94. string(6) "maroon"
  95. }
  96. test insertion
  97. array(0) {
  98. }
  99. array(5) {
  100. [0]=>
  101. string(3) "red"
  102. [1]=>
  103. string(5) "green"
  104. [2]=>
  105. string(4) "blue"
  106. [3]=>
  107. string(6) "purple"
  108. [4]=>
  109. string(6) "yellow"
  110. }