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