shuffle_variation4.phpt 3.7 KB

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