user defined array_chunk()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lipun4u
Forum Commoner
Posts: 82
Joined: Wed Jul 01, 2009 3:35 am
Location: Mumbai
Contact:

user defined array_chunk()

Post by lipun4u »

I want to define a user defined array_chunk(). what is the problem with this code ??

Code: Select all

 
<?php
    header("Content_Type: Text/plain");
    
    function user_array_chunk($arr, $size) {
        $arrs = array();
        $k = -1;
        $i = 0;
        foreach($arr as $ar1) {
            if(($i % $size) == 0) {
                $k ++;
                $j = 0;
                $arrs[k] = array();
            }
            $arrs[k][j++]= $ar1;
        }
        return $arrs;
    }
    $input_array = array('a', 'b', 'c', 'd', 'e');
    print_r(user_array_chunk($input_array, 2));
?>
lipun4u
Forum Commoner
Posts: 82
Joined: Wed Jul 01, 2009 3:35 am
Location: Mumbai
Contact:

Re: user defined array_chunk()

Post by lipun4u »

i fixed the code...

I forgot the $ sign...
Post Reply