shuffle_variation3.phpt 3.3 KB

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