Bladephp: Now with 8+ codeigniter, php, and laravel project 8+ php project From $37/Month From Rs. 2499/Month

PHP array_chunk() Function

by
Category:php
php php array function
PHP array_chunk() Function

The array_chunk() function splits an array into inside of array.

The last chunk may contain less than size elements.

The array_chunk() function splits an array into chunks and stores the chunks into new arrays.

Parameter Description
array Required. Specifies the array to use
size Required. An integer that specifies the size of each chunk
preserve_key Optional. Possible values: true - Preserves the keys, false - Default. Reindexes the chunk numerically
$name = array("Prince","Alex","James","Lachlan","Samuel","Cooper");
print_r(array_chunk($name,2));

Output

Array (
       [0] => Array 
              ( 
                [0] => Prince 
                [1] => Alex 
              ) 
       [1] => Array 
              ( 
                [0] => James 
                [1] => Lachlan 
              ) 
       [2] => Array 
              ( 
                [0] => Samuel 
                [1] => Cooper 
              ) 
      ) 

0 Comments


Html code work in comment box


Related Post