shuffle_variation4.phpt 3.8 KB

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