Answers for "php split array in half"

PHP
2

php chunk array

$array=['a','b','c','d','e','f','g'];
$chunckedArray=array_chunk($array,3);
//output: $chunkedArray=[['a','b','c'],['d','e','f'],['g']]
//Array ( [0] => Array ( [0] => a [1] => b [2] => c ) [1] => Array ( [0] => d [1] => e [2] => f ) [2] => Array ( [0] => g ) )
Posted by: Guest on August-17-2020
0

php split array in half

$alphabet = array("a", "b", "c", "d", "e","f");

$firsthalf = array_slice($alphabet, 0, count($alphabet) / 2);
$secondhalf = array_slice($alphabet, count($alphabet) / 2);
Posted by: Guest on October-13-2021

Browse Popular Code Answers by Language