I have an array full of DB records. It could heaps of elements or very little, it changes regularly.
I need to split the array into two equal parts. The reason is I am then passing these arrays to a Laravel view and displaying them into separate columns.
Here is the DB records being pulled:
$books = Book::where('unitcode', '=', $unitcode['unitcode'])->get();
If the pull works then I'm running this:
return View::make('showbooks')
->with('books', $books);
What I want to do is pass $books1 and $books2 which is actually $books split into 2 parts.
$books = array_chunk($books, count($books)/2);- split it in half $\endgroup$$books = array_chunk($books, count($books)/2, count($books);? $\endgroup$list($books1, $books2) = array_chunk($books, count($books)/2);to get them into variables $\endgroup$array_chunkand it's a odd number of elements, it will create an array with 3 arrays inside of it, not 2 arrays with +1 element in each array. $\endgroup$