Title: array_partition
Author: Scott Reilly
Published: <strong>2009-يىلى 11-ئىيۇن</strong>
Last modified: 2025-يىلى 16-ئاپرېل

---

قىستۇرما ئىزدە

![](https://ps.w.org/array-partition/assets/banner-772x250.png?rev=824324)

![](https://ps.w.org/array-partition/assets/icon-128x128.png?rev=972872)

# array_partition

 يازغۇچى [Scott Reilly](https://profiles.wordpress.org/coffee2code/)

[چۈشۈر](https://downloads.wordpress.org/plugin/array-partition.1.3.5.zip)

 * [تەپسىلاتلار](https://ug.wordpress.org/plugins/array-partition/#description)
 * [باھالاشلار](https://ug.wordpress.org/plugins/array-partition/#reviews)
 *  [ئورنىتىش](https://ug.wordpress.org/plugins/array-partition/#installation)
 * [ئىجادىيەت](https://ug.wordpress.org/plugins/array-partition/#developers)

 [قوللاش](https://wordpress.org/support/plugin/array-partition/)

## چۈشەندۈرۈش

This plugin provides the PHP function `c2c_array_partition()` 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( "aardvark", "bear", "cat", "dog", "emu", "fox", "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] => fox
            )

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

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

Note the array elements are distributed into the requested 4 «columns» as evenly
as possible.

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.

In contrast, using PHP’s built-in `array_chunk()` as such:

    ```
    print_r( array_chunk( $topics, 4 ) );
    ```

Yields:

    ```
    Array
    (
        [0] => Array
            (
                [0] => aardvark
                [1] => bear
                [2] => cat
                [3] => dog
            )
        [1] => Array
            (
                [0] => emu
                [1] => fox
                [2] => gnu
                [3] => hippo
            )
        [2] => Array
            (
                [0] => ibis
                [1] => jackal
            )
    )
    ```

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

Links: [Plugin Homepage](https://coffee2code.com/wp-plugins/array-partition/) | 
[Plugin Directory Page](https://wordpress.org/plugins/array-partition/) | [GitHub](https://github.com/coffee2code/array-partition/)
| [Author Homepage](https://coffee2code.com)

### Examples

    ```
    <?php
      $topics = array( "ant", "bear", "cat" );
      print_r( c2c_array_partition( $topics, 5 ) );
    ?>
    ```

=>

    ```
    Array
    (
        [0] => Array
            (
                [0] => ant
            )

        [1] => Array
            (
                [0] => bear
            )

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

        [3] => Array
            (
            )

        [4] => Array
            (
            )
    )
    ```

Also see Description section for another example. Definitely check out the packaged
unit test file as it contains various examples.

## ئورنىتىش

 1. Install via the built-in WordPress plugin installer. Or download and unzip `array-
    partition.zip` inside the plugins directory for your site (typically `wp-content/
    plugins/`)
 2. Activate the plugin through the ›Plugins‹ admin menu in WordPress
 3. Use the `c2c_array_partition()` function in your template(s) or code as desired.

## FAQ

### Why not use PHP’s built-in `array_chunk()`?

array_chunk() allows you to specify the number of elements per partition, not how
many partitions you want. (See Description.).

For an array with 12 elements, if you requested a chunk size of 2, you would get
back an array of 6 sub-arrays (the original elements grouped into arrays of 2 elements).
With `array_partition()`, if you requested 2 partitions, you would get back an array
of 2 sub-arrays (the original elements grouped into 2 arrays).

Phrased another way, with `array_chunk()` you tell it how many elements max should
be in a partition and it gives you as many partitions as necessary. With `c2c_array_partition()`,
you tell it how many partitions you want, and it’ll evenly split the elements into
those partitions as evenly as possible.

### Does this plugin have unit tests?

Yes. The tests are not packaged in the release .zip file or included in plugins.
svn.wordpress.org, but can be found in the [plugin’s GitHub repository](https://github.com/coffee2code/array-partition/).

## باھالاشلار

بۇ قىستۇرمىغا تېخى باھا يېزىلمىدى.

## تۆھپىكار ۋە ئىجادكار

«array_partition» كودى ئوچۇق يۇمشاق دېتال. تۆۋەندىكى كىشىلەر بۇ قىستۇرمىغا تۆھپە
قوشقان.

تۆھپىكار

 *   [ Scott Reilly ](https://profiles.wordpress.org/coffee2code/)

[«array_partition» نى تىلىڭىزغا تەرجىمە قىلىڭ](https://translate.wordpress.org/projects/wp-plugins/array-partition)

### ئىجادىيەتكە قىزىقامسىز؟

[كودقا كۆز يۈگۈرتۈپ](https://plugins.trac.wordpress.org/browser/array-partition/)،
[SVN خەزىنە](https://plugins.svn.wordpress.org/array-partition/) تەكشۈرۈپ ياكى [RSS](https://plugins.trac.wordpress.org/log/array-partition/?limit=100&mode=stop_on_copy&format=rss)
ئارقىلىق [ئىجادىيەت خاتىرىسى](https://plugins.trac.wordpress.org/log/array-partition/)
گە مۇشتەرى بولغىلى بولىدۇ.

## ئۆزگىرىش خاتىرىسى

#### 1.3.5 (2025-04-16)

 * Change: Use correct value for ›Text Domain‹ in plugin header
 * Change: Note compatibility through WP 6.8+
 * Change: Note compatibility through PHP 8.3+
 * Change: Update copyright date (2025)

#### 1.3.4 (2024-08-02)

 * Change: Note compatibility through WP 6.6+
 * Change: Update copyright date (2024)
 * New: Add `.gitignore` file
 * Change: Reduce number of ›Tags‹ from `readme.txt`
 * Change: Remove development and testing-related files from release packaging
 * Unit tests:
    - Hardening: Prevent direct web access to `bootstrap.php`
    - Allow tests to run against current versions of WordPress
    - New: Add `composer.json` for PHPUnit Polyfill dependency
    - Change: In bootstrap, store path to plugin directory in a constant

#### 1.3.3 (2023-05-21)

 * Change: Note compatibility through WP 6.3+
 * Change: Update copyright date (2023)

_Full changelog is available in [CHANGELOG.md](https://github.com/coffee2code/array-partition/blob/master/CHANGELOG.md)._

## Meta

 *  Version **1.3.5**
 *  ئاخىرقى يېڭىلانغان ۋاقىت **1 يىل بۇرۇن**
 *  ئاكتىپ ئورنىتىش سانى **10+**
 *  WordPress نەشرى ** 1.2 ياكى يۇقىرى **
 *  **6.8.5** دا سىنالغان
 *  تىل
 * [English (US)](https://wordpress.org/plugins/array-partition/)
 * بەلگە
 * [array](https://ug.wordpress.org/plugins/tags/array/)[coffee2code](https://ug.wordpress.org/plugins/tags/coffee2code/)
   [columns](https://ug.wordpress.org/plugins/tags/columns/)
 *  [ئالىي كۆرۈنۈش](https://ug.wordpress.org/plugins/array-partition/advanced/)

## دەرىجە

No reviews have been submitted yet.

[Your review](https://wordpress.org/support/plugin/array-partition/reviews/#new-post)

[بارلىق ئىنكاسنى كۆرسەت](https://wordpress.org/support/plugin/array-partition/reviews/)

## تۆھپىكار

 *   [ Scott Reilly ](https://profiles.wordpress.org/coffee2code/)

## قوللاش

چۈشەندۈرۈشىڭىز بارمۇ؟ ياردەم لازىممۇ؟

 [قوللاش مۇنبىرىنى كۆرسەت](https://wordpress.org/support/plugin/array-partition/)

## ئىئانە

بۇ قىستۇرمىنىڭ ياخشىلىنىشىنى قوللامسىز؟

 [ بۇ قىستۇرمىغا ئىئانە قىلىش ](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6ARCFJ9TX3522)