{"id":5672,"date":"2009-06-11T19:58:34","date_gmt":"2009-06-11T19:58:34","guid":{"rendered":"https:\/\/wordpress.org\/plugins-wp\/array-partition\/"},"modified":"2025-04-16T22:35:59","modified_gmt":"2025-04-16T22:35:59","slug":"array-partition","status":"publish","type":"plugin","link":"https:\/\/pirate.wordpress.org\/plugins\/array-partition\/","author":3606,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","version":"1.3.5","stable_tag":"1.3.5","tested":"6.8.5","requires":"1.2","requires_php":"","requires_plugins":null,"header_name":"array_partition","header_author":"Scott Reilly","header_description":"","assets_banners_color":"0074a2","last_updated":"2025-04-16 22:35:59","external_support_url":"","external_repository_url":"","donate_link":"https:\/\/www.paypal.com\/cgi-bin\/webscr?cmd=_s-xclick&hosted_button_id=6ARCFJ9TX3522","header_plugin_uri":"https:\/\/coffee2code.com\/wp-plugins\/array-partition\/","header_author_uri":"https:\/\/coffee2code.com\/","rating":0,"author_block_rating":0,"active_installs":10,"downloads":4353,"num_ratings":0,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","installation","faq","changelog"],"tags":{"1.0":{"tag":"1.0","author":"coffee2code","date":"2009-06-11 19:58:34"},"1.0.1":{"tag":"1.0.1","author":"coffee2code","date":"2010-01-06 21:15:44"},"1.0.2":{"tag":"1.0.2","author":"coffee2code","date":"2010-08-19 19:28:01"},"1.0.3":{"tag":"1.0.3","author":"coffee2code","date":"2011-02-12 20:00:00"},"1.1":{"tag":"1.1","author":"coffee2code","date":"2011-02-24 21:02:49"},"1.1.1":{"tag":"1.1.1","author":"coffee2code","date":"2011-07-15 14:23:09"},"1.1.2":{"tag":"1.1.2","author":"coffee2code","date":"2011-11-20 16:53:26"},"1.1.3":{"tag":"1.1.3","author":"coffee2code","date":"2012-06-04 15:23:35"},"1.1.4":{"tag":"1.1.4","author":"coffee2code","date":"2012-12-11 17:09:29"},"1.2":{"tag":"1.2","author":"coffee2code","date":"2013-12-18 02:21:30"},"1.2.1":{"tag":"1.2.1","author":"coffee2code","date":"2014-08-26 04:14:51"},"1.2.2":{"tag":"1.2.2","author":"coffee2code","date":"2015-08-23 06:40:54"},"1.2.3":{"tag":"1.2.3","author":"coffee2code","date":"2016-04-14 20:42:42"},"1.2.4":{"tag":"1.2.4","author":"coffee2code","date":"2017-02-04 07:27:26"},"1.2.5":{"tag":"1.2.5","author":"coffee2code","date":"2018-06-15 17:46:36"},"1.2.6":{"tag":"1.2.6","author":"coffee2code","date":"2019-03-14 05:30:37"},"1.2.7":{"tag":"1.2.7","author":"coffee2code","date":"2019-06-20 05:55:52"},"1.2.8":{"tag":"1.2.8","author":"coffee2code","date":"2019-12-07 08:29:17"},"1.2.9":{"tag":"1.2.9","author":"coffee2code","date":"2020-05-05 07:02:10"},"1.3":{"tag":"1.3","author":"coffee2code","date":"2020-09-11 06:51:32"},"1.3.1":{"tag":"1.3.1","author":"coffee2code","date":"2021-04-05 21:01:18"},"1.3.2":{"tag":"1.3.2","author":"coffee2code","date":"2021-09-26 07:02:39"},"1.3.3":{"tag":"1.3.3","author":"coffee2code","date":"2023-08-22 18:02:14"},"1.3.4":{"tag":"1.3.4","author":"coffee2code","date":"2024-08-11 05:30:51"},"1.3.5":{"tag":"1.3.5","author":"coffee2code","date":"2025-04-16 22:35:59"}},"upgrade_notice":{"1.3.5":"<p>Trivial update: fixed value of &#039;Text Domain&#039; plugin header, noted compatibility through WP 6.8+ and PHP 8.3+, and updated copyright date (2025)<\/p>","1.3.4":"<p>Trivial update: noted compatibility through WP 6.6+, removed unit tests from release packaging, and updated copyright date (2024)<\/p>","1.3.3":"<p>Trivial update: noted compatibility through WP 6.3+ and updated copyright date (2023)<\/p>","1.3.2":"<p>Trivial update: noted compatibility through WP 5.8+ and minor reorganization and tweaks to unit tests<\/p>","1.3.1":"<p>Trivial update: noted compatibility through WP 5.7+ and updated copyright date (2021)<\/p>","1.3":"<p>Minor update: Removed long-deprecated function <code>array_partition()<\/code>, restructured unit test file structure, and noted compatibility through WP 5.5+.<\/p>","1.2.9":"<p>Trivial update: Updated a few URLs to be HTTPS and noted compatibility through WP 5.4+.<\/p>","1.2.8":"<p>Trivial update: noted compatibility through WP 5.3+ and updated copyright date (2020)<\/p>","1.2.7":"<p>Trivial update: modernized unit tests and noted compatibility through WP 5.2+<\/p>","1.2.6":"<p>Trivial update: created CHANGELOG.md to store changelog outside of readme.txt, noted compatibility through WP 5.1+, and updated copyright date (2019)<\/p>","1.2.5":"<p>Trivial update: noted compatibility through WP 4.9+, added README.md for GitHub, and updated copyright date (2018)<\/p>","1.2.4":"<p>Trivial update: updated unit test bootstrap file, noted compatibility through WP 4.7+, and updated copyright date<\/p>","1.2.3":"<p>Trivial update: noted compatibility through WP 4.4+ and updated copyright date<\/p>","1.2.2":"<p>Trivial update: noted compatibility through WP 4.1+ and updated copyright date<\/p>","1.2.1":"<p>Trivial update: noted compatibility through WP 4.0+; minor documentation tweaks; added plugin icon<\/p>","1.2":"<p>Minor update: now handle 0, negative, and string numerical values for number_of_columns argument; added unit tests; noted compatibility through WP 3.8+<\/p>","1.1.4":"<p>Trivial update: noted compatibility through WP 3.5+; minor documentation tweaks<\/p>","1.1.3":"<p>Trivial update: noted compatibility through WP 3.4+; explicitly stated license<\/p>","1.1.2":"<p>Trivial update: noted compatibility through WP 3.3+ and minor documentation formatting changes (spacing)<\/p>","1.1.1":"<p>Trivial update: noted compatibility through WP 3.2+ and minor code formatting changes (spacing)<\/p>","1.1":"<p>Minor update: deprecated <code>array_partition()<\/code> in favor of <code>c2c_array_partition()<\/code>; added link to plugin homepage in readme.txt<\/p>","1.0.3":"<p>Trivial update: noted compatibility through WP 3.1+ and updated copyright date<\/p>","1.0.2":"<p>Minor update. Highlights: added <code>if(function_exists())<\/code> check around <code>array_partition()<\/code>; minor text reorganization; added verified WP 3.0 compatibility.<\/p>"},"ratings":{"1":0,"2":0,"3":0,"4":0,"5":0},"assets_icons":{"icon-128x128.png":{"filename":"icon-128x128.png","revision":972872,"resolution":"128x128","location":"assets","locale":""}},"assets_banners":{"banner-772x250.png":{"filename":"banner-772x250.png","revision":824324,"resolution":"772x250","location":"assets","locale":""}},"assets_blueprints":{},"all_blocks":[],"tagged_versions":["1.0","1.0.1","1.0.2","1.0.3","1.1","1.1.1","1.1.2","1.1.3","1.1.4","1.2","1.2.1","1.2.2","1.2.3","1.2.4","1.2.5","1.2.6","1.2.7","1.2.8","1.2.9","1.3","1.3.1","1.3.2","1.3.3","1.3.4","1.3.5"],"block_files":[],"assets_screenshots":[],"screenshots":[],"jetpack_post_was_ever_published":false},"plugin_section":[],"plugin_tags":[8432,131398,2758,854,230536],"plugin_category":[],"plugin_contributors":[78189],"plugin_business_model":[],"class_list":["post-5672","plugin","type-plugin","status-publish","hentry","plugin_tags-array","plugin_tags-chunk","plugin_tags-coffee2code","plugin_tags-columns","plugin_tags-partition","plugin_contributors-coffee2code","plugin_committers-coffee2code"],"banners":{"banner":"https:\/\/ps.w.org\/array-partition\/assets\/banner-772x250.png?rev=824324","banner_2x":false,"banner_rtl":false,"banner_2x_rtl":false},"icons":{"svg":false,"icon":"https:\/\/ps.w.org\/array-partition\/assets\/icon-128x128.png?rev=972872","icon_2x":false,"generated":false},"screenshots":[],"raw_content":"<!--section=description-->\n<p>This plugin provides the PHP function <code>c2c_array_partition()<\/code> to split an array into any number of sub-arrays, suitable for creating evenly distributed, vertically filled \"columns\".  Also known as \"chunking\" or \"partitioning\".<\/p>\n\n<p>For example:<\/p>\n\n<pre><code>$topics = array( \"aardvark\", \"bear\", \"cat\", \"dog\", \"emu\", \"fox\", \"gnu\", \"hippo\", \"ibis\", \"jackal\" );\nprint_r( c2c_array_partition( $topics, 4 ) );\n<\/code><\/pre>\n\n<p>Yields:<\/p>\n\n<pre><code>Array\n(\n    [0] =&gt; Array\n        (\n            [0] =&gt; ant\n            [1] =&gt; bear\n            [2] =&gt; cat\n        )\n\n    [1] =&gt; Array\n        (\n            [0] =&gt; dog\n            [1] =&gt; emu\n            [2] =&gt; fox\n        )\n\n    [2] =&gt; Array\n        (\n            [0] =&gt; gnu\n            [1] =&gt; hippo\n        )\n\n    [3] =&gt; Array\n        (\n            [0] =&gt; ibis\n            [1] =&gt; jackal\n        )\n)\n<\/code><\/pre>\n\n<p>Note the array elements are distributed into the requested 4 \"columns\" as evenly as possible.<\/p>\n\n<p>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.<\/p>\n\n<p>In contrast, using PHP's built-in <code>array_chunk()<\/code> as such:<\/p>\n\n<pre><code>print_r( array_chunk( $topics, 4 ) );\n<\/code><\/pre>\n\n<p>Yields:<\/p>\n\n<pre><code>Array\n(\n    [0] =&gt; Array\n        (\n            [0] =&gt; aardvark\n            [1] =&gt; bear\n            [2] =&gt; cat\n            [3] =&gt; dog\n        )\n    [1] =&gt; Array\n        (\n            [0] =&gt; emu\n            [1] =&gt; fox\n            [2] =&gt; gnu\n            [3] =&gt; hippo\n        )\n    [2] =&gt; Array\n        (\n            [0] =&gt; ibis\n            [1] =&gt; jackal\n        )\n)\n<\/code><\/pre>\n\n<p>It can be sent an array of any data types or objects.<\/p>\n\n<p>Links: <a href=\"https:\/\/coffee2code.com\/wp-plugins\/array-partition\/\">Plugin Homepage<\/a> | <a href=\"https:\/\/wordpress.org\/plugins\/array-partition\/\">Plugin Directory Page<\/a> | <a href=\"https:\/\/github.com\/coffee2code\/array-partition\/\">GitHub<\/a> | <a href=\"https:\/\/coffee2code.com\">Author Homepage<\/a><\/p>\n\n<h3>Examples<\/h3>\n\n<pre><code>&lt;?php\n  $topics = array( \"ant\", \"bear\", \"cat\" );\n  print_r( c2c_array_partition( $topics, 5 ) );\n?&gt;\n<\/code><\/pre>\n\n<p>=&gt;<\/p>\n\n<pre><code>Array\n(\n    [0] =&gt; Array\n        (\n            [0] =&gt; ant\n        )\n\n    [1] =&gt; Array\n        (\n            [0] =&gt; bear\n        )\n\n    [2] =&gt; Array\n        (\n            [0] =&gt; cat\n        )\n\n    [3] =&gt; Array\n        (\n        )\n\n    [4] =&gt; Array\n        (\n        )\n)\n<\/code><\/pre>\n\n<p>Also see Description section for another example. Definitely check out the packaged unit test file as it contains various examples.<\/p>\n\n<!--section=installation-->\n<ol>\n<li>Install via the built-in WordPress plugin installer. Or download and unzip <code>array-partition.zip<\/code> inside the plugins directory for your site (typically <code>wp-content\/plugins\/<\/code>)<\/li>\n<li>Activate the plugin through the 'Plugins' admin menu in WordPress<\/li>\n<li>Use the <code>c2c_array_partition()<\/code> function in your template(s) or code as desired.<\/li>\n<\/ol>\n\n<!--section=faq-->\n<dl>\n<dt id='why%20not%20use%20php%27s%20built-in%20%60array_chunk%28%29%60%3F'><h3>Why not use PHP's built-in `array_chunk()`?<\/h3><\/dt>\n<dd><p>array_chunk() allows you to specify the number of elements per partition, not how many partitions you want. (See Description.).<\/p>\n\n<p>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 <code>array_partition()<\/code>, if you requested 2 partitions, you would get back an array of 2 sub-arrays (the original elements grouped into 2 arrays).<\/p>\n\n<p>Phrased another way, with <code>array_chunk()<\/code> you tell it how many elements max should be in a partition and it gives you as many partitions as necessary. With <code>c2c_array_partition()<\/code>, you tell it how many partitions you want, and it'll evenly split the elements into those partitions as evenly as possible.<\/p><\/dd>\n<dt id='does%20this%20plugin%20have%20unit%20tests%3F'><h3>Does this plugin have unit tests?<\/h3><\/dt>\n<dd><p>Yes. The tests are not packaged in the release .zip file or included in plugins.svn.wordpress.org, but can be found in the <a href=\"https:\/\/github.com\/coffee2code\/array-partition\/\">plugin's GitHub repository<\/a>.<\/p><\/dd>\n\n<\/dl>\n\n<!--section=changelog-->\n<h4>1.3.5 (2025-04-16)<\/h4>\n\n<ul>\n<li>Change: Use correct value for 'Text Domain' in plugin header<\/li>\n<li>Change: Note compatibility through WP 6.8+<\/li>\n<li>Change: Note compatibility through PHP 8.3+<\/li>\n<li>Change: Update copyright date (2025)<\/li>\n<\/ul>\n\n<h4>1.3.4 (2024-08-02)<\/h4>\n\n<ul>\n<li>Change: Note compatibility through WP 6.6+<\/li>\n<li>Change: Update copyright date (2024)<\/li>\n<li>New: Add <code>.gitignore<\/code> file<\/li>\n<li>Change: Reduce number of 'Tags' from <code>readme.txt<\/code><\/li>\n<li>Change: Remove development and testing-related files from release packaging<\/li>\n<li>Unit tests:\n\n<ul>\n<li>Hardening: Prevent direct web access to <code>bootstrap.php<\/code><\/li>\n<li>Allow tests to run against current versions of WordPress<\/li>\n<li>New: Add <code>composer.json<\/code> for PHPUnit Polyfill dependency<\/li>\n<li>Change: In bootstrap, store path to plugin directory in a constant<\/li>\n<\/ul><\/li>\n<\/ul>\n\n<h4>1.3.3 (2023-05-21)<\/h4>\n\n<ul>\n<li>Change: Note compatibility through WP 6.3+<\/li>\n<li>Change: Update copyright date (2023)<\/li>\n<\/ul>\n\n<p><em>Full changelog is available in <a href=\"https:\/\/github.com\/coffee2code\/array-partition\/blob\/master\/CHANGELOG.md\">CHANGELOG.md<\/a>.<\/em><\/p>","raw_excerpt":"Provides a helper function to split an array into N number of evenly distributed partitions (i.e. split a list into N columns)","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/pirate.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/5672","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pirate.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/pirate.wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"author":[{"embeddable":true,"href":"https:\/\/pirate.wordpress.org\/plugins\/wp-json\/wp\/v2\/users\/3606"}],"replies":[{"embeddable":true,"href":"https:\/\/pirate.wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=5672"}],"wp:attachment":[{"href":"https:\/\/pirate.wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=5672"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/pirate.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=5672"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/pirate.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=5672"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/pirate.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=5672"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/pirate.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=5672"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/pirate.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=5672"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}