array_chunk_variation2.phpt 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. --TEST--
  2. Test array_chunk() function : usage variations - unexpected values for 'size' argument
  3. --FILE--
  4. <?php
  5. /* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys])
  6. * Description: Split array into chunks
  7. : Chunks an array into size large chunks
  8. * Source code: ext/standard/array.c
  9. */
  10. /*
  11. * Testing array_chunk() function with unexpected values for 'size' argument
  12. */
  13. echo "*** Testing array_chunk() : usage variations ***\n";
  14. // input array
  15. $input = array(1, 2);
  16. //get an unset variable
  17. $unset_var = 10;
  18. unset ($unset_var);
  19. //array of values to iterate over
  20. $values = array (
  21. // float data
  22. /*1*/ 10.5,
  23. -10.5,
  24. 10.5e10,
  25. 10.6E-10,
  26. .5,
  27. // array data
  28. /*6*/ array(),
  29. array(0),
  30. array(1),
  31. array(1, 2),
  32. array('color' => 'red', 'item' => 'pen'),
  33. // null data
  34. /*11*/ NULL,
  35. null,
  36. // boolean data
  37. /*13*/ true,
  38. false,
  39. TRUE,
  40. FALSE,
  41. // empty data
  42. /*17*/ "",
  43. '',
  44. // string data
  45. /*19*/ "string",
  46. 'string',
  47. // object data
  48. /*21*/ new stdclass(),
  49. // undefined data
  50. /*22*/ @undefined_var,
  51. // unset data
  52. /*23*/ @unset_var
  53. );
  54. // loop through each element of the array for size
  55. $count = 1;
  56. foreach($values as $value){
  57. echo "\n-- Iteration $count --\n";
  58. var_dump( array_chunk($input, $value) );
  59. var_dump( array_chunk($input, $value, true) );
  60. var_dump( array_chunk($input, $value, false) );
  61. $count++;
  62. }
  63. echo "Done";
  64. ?>
  65. --EXPECTF--
  66. *** Testing array_chunk() : usage variations ***
  67. -- Iteration 1 --
  68. array(1) {
  69. [0]=>
  70. array(2) {
  71. [0]=>
  72. int(1)
  73. [1]=>
  74. int(2)
  75. }
  76. }
  77. array(1) {
  78. [0]=>
  79. array(2) {
  80. [0]=>
  81. int(1)
  82. [1]=>
  83. int(2)
  84. }
  85. }
  86. array(1) {
  87. [0]=>
  88. array(2) {
  89. [0]=>
  90. int(1)
  91. [1]=>
  92. int(2)
  93. }
  94. }
  95. -- Iteration 2 --
  96. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  97. NULL
  98. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  99. NULL
  100. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  101. NULL
  102. -- Iteration 3 --
  103. array(1) {
  104. [0]=>
  105. array(2) {
  106. [0]=>
  107. int(1)
  108. [1]=>
  109. int(2)
  110. }
  111. }
  112. array(1) {
  113. [0]=>
  114. array(2) {
  115. [0]=>
  116. int(1)
  117. [1]=>
  118. int(2)
  119. }
  120. }
  121. array(1) {
  122. [0]=>
  123. array(2) {
  124. [0]=>
  125. int(1)
  126. [1]=>
  127. int(2)
  128. }
  129. }
  130. -- Iteration 4 --
  131. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  132. NULL
  133. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  134. NULL
  135. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  136. NULL
  137. -- Iteration 5 --
  138. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  139. NULL
  140. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  141. NULL
  142. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  143. NULL
  144. -- Iteration 6 --
  145. Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
  146. NULL
  147. Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
  148. NULL
  149. Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
  150. NULL
  151. -- Iteration 7 --
  152. Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
  153. NULL
  154. Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
  155. NULL
  156. Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
  157. NULL
  158. -- Iteration 8 --
  159. Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
  160. NULL
  161. Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
  162. NULL
  163. Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
  164. NULL
  165. -- Iteration 9 --
  166. Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
  167. NULL
  168. Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
  169. NULL
  170. Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
  171. NULL
  172. -- Iteration 10 --
  173. Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
  174. NULL
  175. Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
  176. NULL
  177. Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
  178. NULL
  179. -- Iteration 11 --
  180. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  181. NULL
  182. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  183. NULL
  184. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  185. NULL
  186. -- Iteration 12 --
  187. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  188. NULL
  189. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  190. NULL
  191. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  192. NULL
  193. -- Iteration 13 --
  194. array(2) {
  195. [0]=>
  196. array(1) {
  197. [0]=>
  198. int(1)
  199. }
  200. [1]=>
  201. array(1) {
  202. [0]=>
  203. int(2)
  204. }
  205. }
  206. array(2) {
  207. [0]=>
  208. array(1) {
  209. [0]=>
  210. int(1)
  211. }
  212. [1]=>
  213. array(1) {
  214. [1]=>
  215. int(2)
  216. }
  217. }
  218. array(2) {
  219. [0]=>
  220. array(1) {
  221. [0]=>
  222. int(1)
  223. }
  224. [1]=>
  225. array(1) {
  226. [0]=>
  227. int(2)
  228. }
  229. }
  230. -- Iteration 14 --
  231. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  232. NULL
  233. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  234. NULL
  235. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  236. NULL
  237. -- Iteration 15 --
  238. array(2) {
  239. [0]=>
  240. array(1) {
  241. [0]=>
  242. int(1)
  243. }
  244. [1]=>
  245. array(1) {
  246. [0]=>
  247. int(2)
  248. }
  249. }
  250. array(2) {
  251. [0]=>
  252. array(1) {
  253. [0]=>
  254. int(1)
  255. }
  256. [1]=>
  257. array(1) {
  258. [1]=>
  259. int(2)
  260. }
  261. }
  262. array(2) {
  263. [0]=>
  264. array(1) {
  265. [0]=>
  266. int(1)
  267. }
  268. [1]=>
  269. array(1) {
  270. [0]=>
  271. int(2)
  272. }
  273. }
  274. -- Iteration 16 --
  275. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  276. NULL
  277. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  278. NULL
  279. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  280. NULL
  281. -- Iteration 17 --
  282. Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
  283. NULL
  284. Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
  285. NULL
  286. Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
  287. NULL
  288. -- Iteration 18 --
  289. Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
  290. NULL
  291. Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
  292. NULL
  293. Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
  294. NULL
  295. -- Iteration 19 --
  296. Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
  297. NULL
  298. Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
  299. NULL
  300. Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
  301. NULL
  302. -- Iteration 20 --
  303. Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
  304. NULL
  305. Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
  306. NULL
  307. Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
  308. NULL
  309. -- Iteration 21 --
  310. Warning: array_chunk() expects parameter 2 to be long, object given in %s on line %d
  311. NULL
  312. Warning: array_chunk() expects parameter 2 to be long, object given in %s on line %d
  313. NULL
  314. Warning: array_chunk() expects parameter 2 to be long, object given in %s on line %d
  315. NULL
  316. -- Iteration 22 --
  317. Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
  318. NULL
  319. Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
  320. NULL
  321. Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
  322. NULL
  323. -- Iteration 23 --
  324. Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
  325. NULL
  326. Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
  327. NULL
  328. Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
  329. NULL
  330. Done