How to split/divide an array into 2 using php?
Use array_chunk
:
$pieces = array_chunk($array, ceil(count($array) / 2));
If you want them in separate variables (instead of a multi-dimensional array), use list
:
list($array1, $array2) = array_chunk($array, ceil(count($array) / 2));
array_slice
works well as long as you know how many elements you want in each array:
$array1 = array_slice($array, 0, 3);
$array2 = array_slice($array, 3, 3);