Partition Array

Split an array into two groups based on a condition.

Code

General
$even = array_values(array_filter($arr, fn($x) => $x % 2 === 0));
$odd = array_values(array_filter($arr, fn($x) => $x % 2 !== 0));
return [$even, $odd];

Parameters

Array to partition

Server

More PHP Snippets