123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427 |
- --TEST--
- Test array_chunk() function : usage variations - unexpected values for 'size' argument
- --FILE--
- <?php
- /* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys])
- * Description: Split array into chunks
- : Chunks an array into size large chunks
- * Source code: ext/standard/array.c
- */
- /*
- * Testing array_chunk() function with unexpected values for 'size' argument
- */
- echo "*** Testing array_chunk() : usage variations ***\n";
- // input array
- $input = array(1, 2);
- //get an unset variable
- $unset_var = 10;
- unset ($unset_var);
- //array of values to iterate over
- $values = array (
- // float data
- /*1*/ 10.5,
- -10.5,
- 10.5e10,
- 10.6E-10,
- .5,
- // array data
- /*6*/ array(),
- array(0),
- array(1),
- array(1, 2),
- array('color' => 'red', 'item' => 'pen'),
- // null data
- /*11*/ NULL,
- null,
- // boolean data
- /*13*/ true,
- false,
- TRUE,
- FALSE,
- // empty data
- /*17*/ "",
- '',
- // string data
- /*19*/ "string",
- 'string',
- // object data
- /*21*/ new stdclass(),
- // undefined data
- /*22*/ @undefined_var,
- // unset data
- /*23*/ @unset_var
- );
- // loop through each element of the array for size
- $count = 1;
- foreach($values as $value){
- echo "\n-- Iteration $count --\n";
- var_dump( array_chunk($input, $value) );
- var_dump( array_chunk($input, $value, true) );
- var_dump( array_chunk($input, $value, false) );
- $count++;
- }
- echo "Done";
- ?>
- --EXPECTF--
- *** Testing array_chunk() : usage variations ***
- -- Iteration 1 --
- array(1) {
- [0]=>
- array(2) {
- [0]=>
- int(1)
- [1]=>
- int(2)
- }
- }
- array(1) {
- [0]=>
- array(2) {
- [0]=>
- int(1)
- [1]=>
- int(2)
- }
- }
- array(1) {
- [0]=>
- array(2) {
- [0]=>
- int(1)
- [1]=>
- int(2)
- }
- }
- -- Iteration 2 --
- Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
- NULL
- Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
- NULL
- Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
- NULL
- -- Iteration 3 --
- array(1) {
- [0]=>
- array(2) {
- [0]=>
- int(1)
- [1]=>
- int(2)
- }
- }
- array(1) {
- [0]=>
- array(2) {
- [0]=>
- int(1)
- [1]=>
- int(2)
- }
- }
- array(1) {
- [0]=>
- array(2) {
- [0]=>
- int(1)
- [1]=>
- int(2)
- }
- }
- -- Iteration 4 --
- Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
- NULL
- Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
- NULL
- Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
- NULL
- -- Iteration 5 --
- Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
- NULL
- Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
- NULL
- Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
- NULL
- -- Iteration 6 --
- Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
- NULL
- Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
- NULL
- Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
- NULL
- -- Iteration 7 --
- Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
- NULL
- Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
- NULL
- Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
- NULL
- -- Iteration 8 --
- Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
- NULL
- Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
- NULL
- Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
- NULL
- -- Iteration 9 --
- Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
- NULL
- Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
- NULL
- Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
- NULL
- -- Iteration 10 --
- Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
- NULL
- Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
- NULL
- Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
- NULL
- -- Iteration 11 --
- Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
- NULL
- Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
- NULL
- Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
- NULL
- -- Iteration 12 --
- Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
- NULL
- Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
- NULL
- Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
- NULL
- -- Iteration 13 --
- array(2) {
- [0]=>
- array(1) {
- [0]=>
- int(1)
- }
- [1]=>
- array(1) {
- [0]=>
- int(2)
- }
- }
- array(2) {
- [0]=>
- array(1) {
- [0]=>
- int(1)
- }
- [1]=>
- array(1) {
- [1]=>
- int(2)
- }
- }
- array(2) {
- [0]=>
- array(1) {
- [0]=>
- int(1)
- }
- [1]=>
- array(1) {
- [0]=>
- int(2)
- }
- }
- -- Iteration 14 --
- Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
- NULL
- Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
- NULL
- Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
- NULL
- -- Iteration 15 --
- array(2) {
- [0]=>
- array(1) {
- [0]=>
- int(1)
- }
- [1]=>
- array(1) {
- [0]=>
- int(2)
- }
- }
- array(2) {
- [0]=>
- array(1) {
- [0]=>
- int(1)
- }
- [1]=>
- array(1) {
- [1]=>
- int(2)
- }
- }
- array(2) {
- [0]=>
- array(1) {
- [0]=>
- int(1)
- }
- [1]=>
- array(1) {
- [0]=>
- int(2)
- }
- }
- -- Iteration 16 --
- Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
- NULL
- Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
- NULL
- Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
- NULL
- -- Iteration 17 --
- Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
- NULL
- Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
- NULL
- Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
- NULL
- -- Iteration 18 --
- Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
- NULL
- Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
- NULL
- Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
- NULL
- -- Iteration 19 --
- Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
- NULL
- Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
- NULL
- Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
- NULL
- -- Iteration 20 --
- Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
- NULL
- Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
- NULL
- Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
- NULL
- -- Iteration 21 --
- Warning: array_chunk() expects parameter 2 to be long, object given in %s on line %d
- NULL
- Warning: array_chunk() expects parameter 2 to be long, object given in %s on line %d
- NULL
- Warning: array_chunk() expects parameter 2 to be long, object given in %s on line %d
- NULL
- -- Iteration 22 --
- Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
- NULL
- Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
- NULL
- Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
- NULL
- -- Iteration 23 --
- Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
- NULL
- Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
- NULL
- Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
- NULL
- Done
|