php slice array in half

33

$halved = array_chunk($books, ceil(count($books)/2));
<?php
$input_array = array('a', 'b', 'c', 'd', 'e', 'f');
$arrays = array_chunk($input_array, 3);

foreach ($arrays as $array_num => $array) {
  echo "Array $array_num:\n";
  foreach ($array as $item_num => $item) {
    echo "  Item $item_num: $item\n";
  }
}

Comments

Submit
0 Comments