I have an array with a dynamic number of elements (it's a list of words generated by users).
I would like to be able to divide the array elements by 3 at anytime:
My thoughts were to count the elements in the array (using count($myArray)) and if the modulus != 0 I would recursively add elements until it does.
Here is my code:
function adjustArray($myArray, $lineLimit = 3){
$count = count($myArray);
if ($count % $lineLimit != 0):
$myArray[] = '';
adjustArray($myArray, $lineLimit);
else:
return $myArray; //problem when returning is conditional (return won't work - returns NULL
endif;
}
How can I fix this code, or better yet, how can I do this more efficiently?