Re: [RFC] array_partition()
| From: | mickmackusa | Date: | Mon, 26 Oct 2026 12:26:05 +0000 |
| Subject: | Re: [RFC] array_partition() | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-132928@lists.php.net to get a copy of this message | ||
I wouldn't be disappointed to see array_partition() added to the language,
but the longer I think about it, a well-designed
array_group() function
could provide the equivalent behavior as well as afford other than just 2
static groups.
It seems like the only relevant difference is the fact that
array_partition() always returns an indexed array of two arrays without
needing to push 2 empty arrays for padding. Theoretically, array_group()
might not return any subarrays when there are no qualifying items to
retain. Does array_group() need an optional 3rd parameter which declares
an empty array for each nominated grouping key which can be nominated in a
particular order? Food for thought.
Instead of potentially creating array_partition() and eventually
array_group(), I feel any benefits of array_partition() should be baked
into an array_group() function for greater utility in a unified function.
mickmackusa