# [RFC] array_partition()

- Thread: https://externals.io/message/132923
- Original archive: https://news-web.php.net/php.internals/132923
- Started by Ayoub EZZINI on 2026-10-25T13:38:55+00:00
- Messages: 1
- RFC: array_partition() (Under discussion) — https://externals.io/rfc/array_partition.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #132923 — Ayoub EZZINI — 2026-10-25T13:38:55+00:00

URL: https://externals.io/message/132923#132923

Hi internals,

I'd like to start the discussion on a new RFC:

https://wiki.php.net/rfc/array_partition

It proposes a function that splits an array into the elements for which
a callback returns a truthy value and those for which it does not, in a
single pass:

    function array_partition(array $array, callable $callback): array {}

    [$adults, $minors] = array_partition($users, fn($u) => $u->age >= 18);

Keys are preserved, and the callback receives the value and the key,
following `array_find()`. The result is always a list of two arrays, with
the matching elements first, as in Ruby, Kotlin, Rust, Haskell and
Laravel's Collection::partition().

The RFC also covers the points raised in the karma request thread:
why it is a two-way split rather than a general grouping function, why
the result is not keyed by true/false, and the $callback parameter
name. It also discusses the previous userland uses of the name
array_partition() with an "N chunks" meaning.

The implementation is at https://github.com/php/php-src/pull/24568.

Thanks to Ilija for granting the karma, and to everyone who commented
on the earlier thread. I look forward to your feedback.

Ayoub
