# RFC karma request: array_partition()

- Thread: https://externals.io/message/132902
- Original archive: https://news-web.php.net/php.internals/132902
- Started by Ayoub EZZINI on 2026-10-22T18:50:19+00:00
- Messages: 1
- 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

---

## #132902 — Ayoub EZZINI — 2026-10-22T18:50:19+00:00

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

Hi internals,

I'd like to request RFC karma on the wiki to propose a new function,
array_partition(). My wiki username is: ayoubezzini

The function splits an array into the elements that satisfy a callback
and those that don't, in a single pass:

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

It returns [$matching, $nonMatching], preserves keys, and takes the same
$mode argument (ARRAY_FILTER_USE_KEY / ARRAY_FILTER_USE_BOTH) as
 `array_filter()`. Today the same result needs two `array_filter()` passes
with a negated callback, or `array_filter()` followed by `array_diff_key()`.
The same operation exists as Laravel's Collection::partition(), Ruby's
Enumerable#partition, Kotlin's partition and Rust's Iterator::partition.

An implementation with tests is available as a draft PR:
https://github.com/php/php-src/pull/24568

I'll open the formal [RFC] discussion thread once the wiki page is up.

Thanks,
Ayoub Ezzini
