array_chunk() :- Split an array into number of arrays

It will returns a multidimensional numerically indexed array,it starts with zero, with each dimension containing size elements.

<?php
$a=array(“day1″=>”Monday”,”day2″=>”Tuesday”,”day3″=>”Wednesday”,”day4″=>”Thursday”,”day5″=>”Friday”);
$val = array_chunk($a,2);
echo “<pre>”;
print_r($val);
echo “</pre>”;
?>

Output :-

Array
(
    [0] => Array
        (
            [0] => Monday
            [1] => Tuesday
        )

    [1] => Array
        (
            [0] => Wednesday
            [1] => Thursday
        )

    [2] => Array
        (
            [0] => Friday
        )

)

It will divide whole array into sub array & every array contains 2 elements.
It will return an array which contains 2 elements for each array.
Advertisements

I like to hear from you about this !!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s