shuffle_variation2.phpt 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. --TEST--
  2. Test shuffle() function : usage variation - with MultiDimensional array
  3. --FILE--
  4. <?php
  5. /* Prototype : bool shuffle(array $array_arg)
  6. * Description: Randomly shuffle the contents of an array
  7. * Source code: ext/standard/array.c
  8. */
  9. /*
  10. * Test behaviour of shuffle() function when multi-dimensional array is
  11. * passed to 'array_arg' argument
  12. */
  13. echo "*** Testing shuffle() : with multi-dimensional array ***\n";
  14. // initialise the multi-dimensional array
  15. $array_arg = array(
  16. array(1, 2, 3),
  17. array(4, 5, 6),
  18. array(7, 8, 9),
  19. array(10000, 20000000, 30000000),
  20. array(0, 0, 0),
  21. array(012, 023, 034),
  22. array(0x1, 0x0, 0xa)
  23. );
  24. // calling shuffle() function with multi-dimensional array
  25. var_dump( shuffle($array_arg) );
  26. echo "\nThe output array is:\n";
  27. var_dump( $array_arg );
  28. // looping to test shuffle() with each sub-array in the multi-dimensional array
  29. echo "\n*** Testing shuffle() with arrays having different types of values ***\n";
  30. $counter = 1;
  31. for($i=0; $i<=6; $i++) {
  32. echo "\n-- Iteration $counter --\n";
  33. var_dump( shuffle($array_arg[$i]) );
  34. echo "\nThe output array is:\n";
  35. var_dump( $array_arg[$i] );
  36. $counter++;
  37. }
  38. echo "Done";
  39. ?>
  40. --EXPECTF--
  41. *** Testing shuffle() : with multi-dimensional array ***
  42. bool(true)
  43. The output array is:
  44. array(7) {
  45. [0]=>
  46. array(3) {
  47. [0]=>
  48. int(%d)
  49. [1]=>
  50. int(%d)
  51. [2]=>
  52. int(%d)
  53. }
  54. [1]=>
  55. array(3) {
  56. [0]=>
  57. int(%d)
  58. [1]=>
  59. int(%d)
  60. [2]=>
  61. int(%d)
  62. }
  63. [2]=>
  64. array(3) {
  65. [0]=>
  66. int(%d)
  67. [1]=>
  68. int(%d)
  69. [2]=>
  70. int(%d)
  71. }
  72. [3]=>
  73. array(3) {
  74. [0]=>
  75. int(%d)
  76. [1]=>
  77. int(%d)
  78. [2]=>
  79. int(%d)
  80. }
  81. [4]=>
  82. array(3) {
  83. [0]=>
  84. int(%d)
  85. [1]=>
  86. int(%d)
  87. [2]=>
  88. int(%d)
  89. }
  90. [5]=>
  91. array(3) {
  92. [0]=>
  93. int(%d)
  94. [1]=>
  95. int(%d)
  96. [2]=>
  97. int(%d)
  98. }
  99. [6]=>
  100. array(3) {
  101. [0]=>
  102. int(%d)
  103. [1]=>
  104. int(%d)
  105. [2]=>
  106. int(%d)
  107. }
  108. }
  109. *** Testing shuffle() with arrays having different types of values ***
  110. -- Iteration 1 --
  111. bool(true)
  112. The output array is:
  113. array(3) {
  114. [0]=>
  115. int(%d)
  116. [1]=>
  117. int(%d)
  118. [2]=>
  119. int(%d)
  120. }
  121. -- Iteration 2 --
  122. bool(true)
  123. The output array is:
  124. array(3) {
  125. [0]=>
  126. int(%d)
  127. [1]=>
  128. int(%d)
  129. [2]=>
  130. int(%d)
  131. }
  132. -- Iteration 3 --
  133. bool(true)
  134. The output array is:
  135. array(3) {
  136. [0]=>
  137. int(%d)
  138. [1]=>
  139. int(%d)
  140. [2]=>
  141. int(%d)
  142. }
  143. -- Iteration 4 --
  144. bool(true)
  145. The output array is:
  146. array(3) {
  147. [0]=>
  148. int(%d)
  149. [1]=>
  150. int(%d)
  151. [2]=>
  152. int(%d)
  153. }
  154. -- Iteration 5 --
  155. bool(true)
  156. The output array is:
  157. array(3) {
  158. [0]=>
  159. int(%d)
  160. [1]=>
  161. int(%d)
  162. [2]=>
  163. int(%d)
  164. }
  165. -- Iteration 6 --
  166. bool(true)
  167. The output array is:
  168. array(3) {
  169. [0]=>
  170. int(%d)
  171. [1]=>
  172. int(%d)
  173. [2]=>
  174. int(%d)
  175. }
  176. -- Iteration 7 --
  177. bool(true)
  178. The output array is:
  179. array(3) {
  180. [0]=>
  181. int(%d)
  182. [1]=>
  183. int(%d)
  184. [2]=>
  185. int(%d)
  186. }
  187. Done