Plugin Directory

array_partition

Version: 1.1.1 Introduces function c2c_array_partition() to split an array into N number of evenly distributed partitions (useful for splitting a lis

Download Version 1.1.2

Introduces function c2c_array_partition() to split an array into N number of evenly distributed partitions (useful for splitting a list into columns).

This plugin provides a PHP function to split an array into any number of sub-arrays, suitable for creating evenly distributed (vertically filled) "columns". Also known as "chunking" or "partitioning".

For example:

$topics = array( "ant", "bear", "cat", "dog", "emu", "frog", "gnu", "hippo", "ibis", "jackal");
print_r(c2c_array_partition($topics, 4));

Yields:

Array
(
    [0] => Array
        (
            [0] => ant
            [1] => bear
            [2] => cat
        )

    [1] => Array
        (
            [0] => dog
            [1] => emu
            [2] => frog
        )

    [2] => Array
        (
            [0] => gnu
            [1] => hippo
        )

    [3] => Array
        (
            [0] => ibis
            [1] => jackal
        )
)

The function will fill as many partitions as requested, as long as there are enough elements in the array to do so. Any remaining unfilled partitions will be represented as empty arrays.

It can be sent an array of any data types or objects.

Links: Plugin Homepage | Author Homepage

Author: coffee2code
Tags:

Requires: 1.2 or higher
Compatible up to: 3.3.1
Last Updated: 2011-7-15 Downloads: 250

Average Rating

5 stars
4 stars
3 stars
2 stars
1 star
(1 ratings)

Compatibility

+
=
Not enough data

0 people say it works.
0 people say it's broken.

Log in to vote.

100,1,1
100,1,1
100,1,1
100,1,1
100,1,1