shuffle_variation3.phpt 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. --TEST--
  2. Test shuffle() function : usage variation - arrays with diff types of values
  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 arrays having different
  11. * types of values, are passed to 'array_arg' argument
  12. */
  13. echo "*** Testing shuffle() : arrays with diff types of values ***\n";
  14. // initialise different arrays
  15. $array_arg = array(
  16. // array with positive int values
  17. /*1*/ array(0, 1, 2, 2147483647 ),
  18. // array with negative int values
  19. array(-1, -2, -2147483647 ),
  20. // array with positive float values
  21. /*3*/ array(0.23, 1.34, 0e2, 200e-2, 30e2, 10e0, 2147473648.90),
  22. // array with negative float values
  23. array(-0.23, -1.34, -200e-2, -30e2, -10e0, -2147473649.80),
  24. // array with single quoted and double quoted strings
  25. /*5*/ array('one', "123numbers", 'hello\tworld', "hello world\0", '12.34floatnum'),
  26. // array with bool values
  27. array(true, TRUE, FALSE, false),
  28. // array with positive hexa values
  29. /*7*/ array(0x123, 0xabc, 0xABC, 0xac, 0xAb1, 0x9fa),
  30. // array with negative hexa values
  31. array(-0x123, -0xabc, -0xABC, -0xAb1, -0x9fa),
  32. // array with positive octal values
  33. /*9*/ array(0123, 02348, 034, 00),
  34. // array with negative octal values
  35. /*10*/ array(-0123, -02348, -034),
  36. );
  37. // looping to test shuffle() with each sub-array in the $array_arg array
  38. echo "\n*** Testing shuffle() with arrays having different types of values ***\n";
  39. $counter = 1;
  40. foreach($array_arg as $arr) {
  41. echo "\n-- Iteration $counter --\n";
  42. var_dump( shuffle($arr) );
  43. echo "\nThe output array is:\n";
  44. var_dump( $arr );
  45. $counter++;
  46. }
  47. echo "Done";
  48. ?>
  49. --EXPECTF--
  50. *** Testing shuffle() : arrays with diff types of values ***
  51. *** Testing shuffle() with arrays having different types of values ***
  52. -- Iteration 1 --
  53. bool(true)
  54. The output array is:
  55. array(4) {
  56. [0]=>
  57. int(%d)
  58. [1]=>
  59. int(%d)
  60. [2]=>
  61. int(%d)
  62. [3]=>
  63. int(%d)
  64. }
  65. -- Iteration 2 --
  66. bool(true)
  67. The output array is:
  68. array(3) {
  69. [0]=>
  70. int(-%d)
  71. [1]=>
  72. int(-%d)
  73. [2]=>
  74. int(-%d)
  75. }
  76. -- Iteration 3 --
  77. bool(true)
  78. The output array is:
  79. array(7) {
  80. [0]=>
  81. float(%f)
  82. [1]=>
  83. float(%f)
  84. [2]=>
  85. float(%f)
  86. [3]=>
  87. float(%f)
  88. [4]=>
  89. float(%f)
  90. [5]=>
  91. float(%f)
  92. [6]=>
  93. float(%f)
  94. }
  95. -- Iteration 4 --
  96. bool(true)
  97. The output array is:
  98. array(6) {
  99. [0]=>
  100. float(-%f)
  101. [1]=>
  102. float(-%f)
  103. [2]=>
  104. float(-%f)
  105. [3]=>
  106. float(-%f)
  107. [4]=>
  108. float(-%f)
  109. [5]=>
  110. float(-%f)
  111. }
  112. -- Iteration 5 --
  113. bool(true)
  114. The output array is:
  115. array(5) {
  116. [0]=>
  117. string(%d) "%s"
  118. [1]=>
  119. string(%d) "%s"
  120. [2]=>
  121. string(%d) "%s"
  122. [3]=>
  123. string(%d) "%s"
  124. [4]=>
  125. string(%d) "%s"
  126. }
  127. -- Iteration 6 --
  128. bool(true)
  129. The output array is:
  130. array(4) {
  131. [0]=>
  132. bool(%s)
  133. [1]=>
  134. bool(%s)
  135. [2]=>
  136. bool(%s)
  137. [3]=>
  138. bool(%s)
  139. }
  140. -- Iteration 7 --
  141. bool(true)
  142. The output array is:
  143. array(6) {
  144. [0]=>
  145. int(%d)
  146. [1]=>
  147. int(%d)
  148. [2]=>
  149. int(%d)
  150. [3]=>
  151. int(%d)
  152. [4]=>
  153. int(%d)
  154. [5]=>
  155. int(%d)
  156. }
  157. -- Iteration 8 --
  158. bool(true)
  159. The output array is:
  160. array(5) {
  161. [0]=>
  162. int(-%d)
  163. [1]=>
  164. int(-%d)
  165. [2]=>
  166. int(-%d)
  167. [3]=>
  168. int(-%d)
  169. [4]=>
  170. int(-%d)
  171. }
  172. -- Iteration 9 --
  173. bool(true)
  174. The output array is:
  175. array(4) {
  176. [0]=>
  177. int(%d)
  178. [1]=>
  179. int(%d)
  180. [2]=>
  181. int(%d)
  182. [3]=>
  183. int(%d)
  184. }
  185. -- Iteration 10 --
  186. bool(true)
  187. The output array is:
  188. array(3) {
  189. [0]=>
  190. int(-%d)
  191. [1]=>
  192. int(-%d)
  193. [2]=>
  194. int(-%d)
  195. }
  196. Done