array_splice_variation1.phpt 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. --TEST--
  2. Test array_splice() function : usage variations - references
  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 "test behaviour when input array is in a reference set\n";
  10. $input_array=array (array(1,2));
  11. $input_array[]=&$input_array[0];
  12. var_dump (array_splice ($input_array[0],1,1));
  13. var_dump ($input_array);
  14. echo "Test behaviour of input arrays containing references \n";
  15. /*
  16. * There are three regions to test:, before cut, the cut and after the cut.
  17. * For reach we check a plain value, a reference value with integer key and a
  18. * reference value with a string key.
  19. */
  20. $numbers=array(0,1,2,3,4,5,6,7,8,9,10,11,12);
  21. $input_array=array(0,1,&$numbers[2],"three"=>&$numbers[3],4,&$numbers[5],"six"=>&$numbers[6],7,&$numbers[8],"nine"=>&$numbers[9]);
  22. var_dump (array_splice ($input_array,4,3));
  23. var_dump ($input_array);
  24. echo "Test behaviour of replacement array containing references \n";
  25. $three=3;
  26. $four=4;
  27. $input_array=array (0,1,2);
  28. $b=array(&$three,"fourkey"=>&$four);
  29. array_splice ($input_array,-1,1,$b);
  30. var_dump ($input_array);
  31. echo "Test behaviour of replacement which is part of reference set \n";
  32. $int=3;
  33. $input_array=array (1,2);
  34. $b=&$int;
  35. array_splice ($input_array,-1,1,$b);
  36. var_dump ($input_array);
  37. echo "Done\n";
  38. ?>
  39. --EXPECT--
  40. test behaviour when input array is in a reference set
  41. array(1) {
  42. [0]=>
  43. int(2)
  44. }
  45. array(2) {
  46. [0]=>
  47. &array(1) {
  48. [0]=>
  49. int(1)
  50. }
  51. [1]=>
  52. &array(1) {
  53. [0]=>
  54. int(1)
  55. }
  56. }
  57. Test behaviour of input arrays containing references
  58. array(3) {
  59. [0]=>
  60. int(4)
  61. [1]=>
  62. &int(5)
  63. ["six"]=>
  64. &int(6)
  65. }
  66. array(7) {
  67. [0]=>
  68. int(0)
  69. [1]=>
  70. int(1)
  71. [2]=>
  72. &int(2)
  73. ["three"]=>
  74. &int(3)
  75. [3]=>
  76. int(7)
  77. [4]=>
  78. &int(8)
  79. ["nine"]=>
  80. &int(9)
  81. }
  82. Test behaviour of replacement array containing references
  83. array(4) {
  84. [0]=>
  85. int(0)
  86. [1]=>
  87. int(1)
  88. [2]=>
  89. &int(3)
  90. [3]=>
  91. &int(4)
  92. }
  93. Test behaviour of replacement which is part of reference set
  94. array(2) {
  95. [0]=>
  96. int(1)
  97. [1]=>
  98. int(3)
  99. }
  100. Done