Okay, so I have a function I'm trying to write that takes an array of n values. If the number of values is even, then I simply call array_chunk() to split them into two different arrays. But, if the number of values is even, then I still need two arrays. array_chunk won't do that, so I need to do it myself. What I'm doing is this (code will follow): First I pop the last value off the array and stick it into a variable. Then I get the count / 2 of the resulting array and array_chunk() it. What I'm trying to do next is tag on the popped value onto the end of the second of the array_chunks. Here's the code:
function splitArray($array)
{
if ((count($array) % 2) != 0) { // odd number of values
$oddVal = array_pop($array);
$count = count($array) / 2;
$chunkArray = array_chunk($array, $count);
// this is the line giving me an error
$chunkArray[1] = $oddVal;
$finalArray = array("pool1" => $chunkArray[0], "pool2" => $chunkArray[1]);
}
else {
// simply call array_chunk on the array in the middle as above, filling the final array with each resulting array
}
}
What am I doing wrong? The error this is giving me is a Parse error: parse error, unexpected ',' in /arraytest.php on line 14 (line 14 is the line where I'm assigning the popped value to the second chunkArray).
Any help would be awesome. Thanks!
James