Answers for "php slice array in half"

PHP
0

php slice array in half

$halved = array_chunk($books, ceil(count($books)/2));
Posted by: Guest on October-02-2021
0

php slice array in half

<?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";
  }
}
Posted by: Guest on October-02-2021

Browse Popular Code Answers by Language