Splitting an array into the items that pass a check and the items that don't is a common job, and PHP has no function for it. Today you call array_filter() twice with the condition flipped, pair array_filter() with array_diff_key(), or write a foreach loop. Ayoub Ezzini's RFC adds array_partition() to do it in one call.
Show me
// Today $adults = array_filter($users, fn($u) => $u->age >= 18); $minors = array_filter($users, fn($u) => $u->age < 18); // Proposed [$adults, $minors] = array_partition($users, fn($u) => $u->age >= 18);
The callback gets both the value and the key, so you can split on either:
[$named, $indexed] = array_partition( ['a' => 1, 'b' => 2, 5 => 3, 6 => 4], fn($value, $key) => is_string($key), ); // $named = ['a' => 1, 'b' => 2] // $indexed = [5 => 3, 6 => 4]
How it works
- Always two arrays. The result is a list: index
0holds the elements the callback accepted, index1holds the rest. An empty input gives[[], []], so destructuring always works. - Keys and order are kept in both arrays, and the input isn't changed.
- Same rules as
array_filter(). The callback's return value is treated as true or false the usual way, and the first array is identical to whatarray_filter($array, $callback, ARRAY_FILTER_USE_BOTH)returns. - Callback signature like
array_find(). It always receives the value and the key, with no$modeparameter. A closure that only takes the value still works, but a built-in function with a fixed number of arguments doesn't.array_partition($a, 'is_string')throws anArgumentCountError, so wrap it infn($v) => is_string($v).
The matching elements come first because that's the order Laravel's Collection::partition(), Ruby, Kotlin, Rust and Haskell all use. The RFC warns against destructuring with true and false keys: PHP turns true into 1, so [true => $passed, false => $rejected] puts the rejected items in $passed.
One question is still open: references. Like array_filter(), the native function keeps an element that is a reference in the input as a reference in the result, so writing to it through the result changes the input. The author asks whether to keep that or drop references, which would be a one-line change.
The RFC doesn't cover general grouping by a key. That's a separate idea, the older array_group RFC, and the author says the two don't conflict.
What it means for existing code
The function name becomes taken in the global namespace. If your code declares its own global array_partition() without a function_exists() check, it fails with "Cannot redeclare function". With the check, your version is quietly skipped and PHP's is used instead, which may behave differently. Some older userland versions used the name to split an array into N chunks, which is a different job. Calls like array_partition($posts, 3) would now throw a TypeError, and array_chunk() already covers that case.
On the author's benchmark it runs about as fast as array_filter() plus array_diff_key(), and about twice as fast as calling array_filter() twice.
Where it stands
Ayoub Ezzini opened the internals discussion on October 25, 2026. The RFC targets PHP 8.7, and the implementation is up as a php-src pull request. A vote would need a two-thirds majority.