View Single Post
  #3 (permalink)  
Old 04-18-2008, 03:19 AM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,162
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default Re: Operations in PHP

Split an array into chunks

To split an array into smaller chunks or smaller sized arrays, we use array_chunk() function of PHP. This will return arrays of several smaller sizes and each array's index number will start with zero unless you want to use the preserve_keys parameter to preserve the original index numbers from the input array used. The syntax is:
array_chunk ( array input, int size [, bool preserve_keys] )

Using the above function in an example:

PHP Code:
<?
$my_array 
= array("One""Two""Three""Four");
$split_array array_chunk($my_array2);
print_r($split_array);
//Output: Array ( 
//                [0] => Array ( 
//                              [0] => One 
//                              [1] => Two ) 
//                [1] => Array ( 
//                              [0] => Three 
//                              [1] => Four ) 
//                               ) 
?>
__________________
With,
J. Jeyaseelan

Everything Possible
Reply With Quote