-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadme.txt
More file actions
249 lines (177 loc) · 7.87 KB
/
readme.txt
File metadata and controls
249 lines (177 loc) · 7.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
=== array_partition ===
Contributors: coffee2code
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6ARCFJ9TX3522
Tags: columns, array, partition, chunk, coffee2code
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Requires at least: 1.2
Tested up to: 6.8
Stable tag: 1.3.5
Provides a helper function to split an array into N number of evenly distributed partitions (i.e. split a list into N columns)
== Description ==
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)
== Installation ==
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/`)
1. Activate the plugin through the 'Plugins' admin menu in WordPress
1. Use the `c2c_array_partition()` function in your template(s) or code as desired.
== 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.
== Frequently Asked Questions ==
= 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/).
== Changelog ==
= 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)._
== Upgrade Notice ==
= 1.3.5 =
Trivial update: fixed value of 'Text Domain' plugin header, noted compatibility through WP 6.8+ and PHP 8.3+, and updated copyright date (2025)
= 1.3.4 =
Trivial update: noted compatibility through WP 6.6+, removed unit tests from release packaging, and updated copyright date (2024)
= 1.3.3 =
Trivial update: noted compatibility through WP 6.3+ and updated copyright date (2023)
= 1.3.2 =
Trivial update: noted compatibility through WP 5.8+ and minor reorganization and tweaks to unit tests
= 1.3.1 =
Trivial update: noted compatibility through WP 5.7+ and updated copyright date (2021)
= 1.3 =
Minor update: Removed long-deprecated function `array_partition()`, restructured unit test file structure, and noted compatibility through WP 5.5+.
= 1.2.9 =
Trivial update: Updated a few URLs to be HTTPS and noted compatibility through WP 5.4+.
= 1.2.8 =
Trivial update: noted compatibility through WP 5.3+ and updated copyright date (2020)
= 1.2.7 =
Trivial update: modernized unit tests and noted compatibility through WP 5.2+
= 1.2.6 =
Trivial update: created CHANGELOG.md to store changelog outside of readme.txt, noted compatibility through WP 5.1+, and updated copyright date (2019)
= 1.2.5 =
Trivial update: noted compatibility through WP 4.9+, added README.md for GitHub, and updated copyright date (2018)
= 1.2.4 =
Trivial update: updated unit test bootstrap file, noted compatibility through WP 4.7+, and updated copyright date
= 1.2.3 =
Trivial update: noted compatibility through WP 4.4+ and updated copyright date
= 1.2.2 =
Trivial update: noted compatibility through WP 4.1+ and updated copyright date
= 1.2.1 =
Trivial update: noted compatibility through WP 4.0+; minor documentation tweaks; added plugin icon
= 1.2 =
Minor update: now handle 0, negative, and string numerical values for number_of_columns argument; added unit tests; noted compatibility through WP 3.8+
= 1.1.4 =
Trivial update: noted compatibility through WP 3.5+; minor documentation tweaks
= 1.1.3 =
Trivial update: noted compatibility through WP 3.4+; explicitly stated license
= 1.1.2 =
Trivial update: noted compatibility through WP 3.3+ and minor documentation formatting changes (spacing)
= 1.1.1 =
Trivial update: noted compatibility through WP 3.2+ and minor code formatting changes (spacing)
= 1.1 =
Minor update: deprecated `array_partition()` in favor of `c2c_array_partition()`; added link to plugin homepage in readme.txt
= 1.0.3 =
Trivial update: noted compatibility through WP 3.1+ and updated copyright date
= 1.0.2 =
Minor update. Highlights: added `if(function_exists())` check around `array_partition()`; minor text reorganization; added verified WP 3.0 compatibility.