This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.

This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.
17 10, 2009

array_chunk

By | 2009-10-30T15:45:53+00:00 October 17th, 2009|Categories: PHP, Ruby|Tags: , , , |2 Comments

The array_chunk() function in PHP splits an array into multiple smaller arrays (array chunks).

PHP

$langs = array('php', 'ruby', 'java', 'perl', 'csharp');
$my_size = 2;
var_dump( array_chunk($langs, $my_size) );

/*
Array (
    [0] => Array
        (
            [0] => php
            [1] => ruby
        )

    [1] => Array
        (
            [0] => java
            [1] => perl
        )

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

) )
*/

Ruby

def array_chunk(full_array, size)
        number_of_chunks = (full_array.length/size.to_f).ceil;
        chunks = (1..number_of_chunks).collect { [] }
            while full_array.any?
              chunks.each do |a_chunk|
                a_chunk << full_array.shift if full_array.any?
              end
            end
        chunks
end

langs = ["php", "ruby", "java", "perl", "csharp"]
my_size = 2
p array_chunk(langs, my_size)

# => [["php", "perl"], ["ruby", "csharp"], ["java"]]