Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to splits an array into chunks of new arrays

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 110
    Comment on it

    Hello Readers ,

    If we want to split one array into bunches of new arrays then their is a PHP function named "array_chunk()" that we can use.

    The array_chunk() function splits an array into chunks of new arrays.

    <!DOCTYPE html>
    <html>
    <body>
    
    <?php
    $age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43","Harry"=>"50");
    print_r(array_chunk($age,2,true));
    ?>
    
    </body>
    </html>
    

    Output:

     Array ( [0] => Array ( [Peter] => 35 [Ben] => 37 ) [1] => Array ( [Joe] => 43 [Harry] => 50 ) ) 
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: