array_chunk2.phpt 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. --TEST--
  2. basic array_chunk test
  3. --FILE--
  4. <?php
  5. $input_array = array('a', 'b', 'c', 'd', 'e');
  6. try {
  7. var_dump(array_chunk($input_array, 0));
  8. } catch (\ValueError $e) {
  9. echo $e->getMessage() . "\n";
  10. }
  11. try {
  12. var_dump(array_chunk($input_array, 0, true));
  13. } catch (\ValueError $e) {
  14. echo $e->getMessage() . "\n";
  15. }
  16. var_dump(array_chunk($input_array, 1));
  17. var_dump(array_chunk($input_array, 1, true));
  18. var_dump(array_chunk($input_array, 2));
  19. var_dump(array_chunk($input_array, 2, true));
  20. var_dump(array_chunk($input_array, 10));
  21. var_dump(array_chunk($input_array, 10, true));
  22. ?>
  23. --EXPECT--
  24. array_chunk(): Argument #2 ($length) must be greater than 0
  25. array_chunk(): Argument #2 ($length) must be greater than 0
  26. array(5) {
  27. [0]=>
  28. array(1) {
  29. [0]=>
  30. string(1) "a"
  31. }
  32. [1]=>
  33. array(1) {
  34. [0]=>
  35. string(1) "b"
  36. }
  37. [2]=>
  38. array(1) {
  39. [0]=>
  40. string(1) "c"
  41. }
  42. [3]=>
  43. array(1) {
  44. [0]=>
  45. string(1) "d"
  46. }
  47. [4]=>
  48. array(1) {
  49. [0]=>
  50. string(1) "e"
  51. }
  52. }
  53. array(5) {
  54. [0]=>
  55. array(1) {
  56. [0]=>
  57. string(1) "a"
  58. }
  59. [1]=>
  60. array(1) {
  61. [1]=>
  62. string(1) "b"
  63. }
  64. [2]=>
  65. array(1) {
  66. [2]=>
  67. string(1) "c"
  68. }
  69. [3]=>
  70. array(1) {
  71. [3]=>
  72. string(1) "d"
  73. }
  74. [4]=>
  75. array(1) {
  76. [4]=>
  77. string(1) "e"
  78. }
  79. }
  80. array(3) {
  81. [0]=>
  82. array(2) {
  83. [0]=>
  84. string(1) "a"
  85. [1]=>
  86. string(1) "b"
  87. }
  88. [1]=>
  89. array(2) {
  90. [0]=>
  91. string(1) "c"
  92. [1]=>
  93. string(1) "d"
  94. }
  95. [2]=>
  96. array(1) {
  97. [0]=>
  98. string(1) "e"
  99. }
  100. }
  101. array(3) {
  102. [0]=>
  103. array(2) {
  104. [0]=>
  105. string(1) "a"
  106. [1]=>
  107. string(1) "b"
  108. }
  109. [1]=>
  110. array(2) {
  111. [2]=>
  112. string(1) "c"
  113. [3]=>
  114. string(1) "d"
  115. }
  116. [2]=>
  117. array(1) {
  118. [4]=>
  119. string(1) "e"
  120. }
  121. }
  122. array(1) {
  123. [0]=>
  124. array(5) {
  125. [0]=>
  126. string(1) "a"
  127. [1]=>
  128. string(1) "b"
  129. [2]=>
  130. string(1) "c"
  131. [3]=>
  132. string(1) "d"
  133. [4]=>
  134. string(1) "e"
  135. }
  136. }
  137. array(1) {
  138. [0]=>
  139. array(5) {
  140. [0]=>
  141. string(1) "a"
  142. [1]=>
  143. string(1) "b"
  144. [2]=>
  145. string(1) "c"
  146. [3]=>
  147. string(1) "d"
  148. [4]=>
  149. string(1) "e"
  150. }
  151. }