How to split the following two-dimensional array into several arrays {code ...} $ arrnew [0] array ({code ...}); $ arrnew [1] array ({code ...}); $ arrnew [2] array ({code ...}); how to split the following two-dimensional array into several arrays
$ Arr = array ('id' => 1, 'User _ name' => 'test1'), array ('id' => 2, 'user _ name' => 'test2'), array ('id' => 3, 'User _ name' => 'test3 '),, array ('id' => 4, 'User _ name' => 'test2'), array ('id' => 5, 'user _ name' => 'test3'); after the split, the number is not certain, and two or three in each group are not necessarily
$ Arrnew [0] = array (
array('id' => 1,'user_name'=>'test1'),array('id' => 2,'user_name'=>'test2')
);
$ Arrnew [1] = array (
array('id' => 3,'user_name'=>'test3'),,array('id' => 4,'user_name'=>'test2')
);
$ Arrnew [2] = array (
Array (
'id' => 5,'user_name'=>'test3')
);
Reply content:
How to split the following two-dimensional array into several arrays
$ Arr = array ('id' => 1, 'User _ name' => 'test1'), array ('id' => 2, 'user _ name' => 'test2'), array ('id' => 3, 'User _ name' => 'test3 '),, array ('id' => 4, 'User _ name' => 'test2'), array ('id' => 5, 'user _ name' => 'test3'); after the split, the number is not certain, and two or three in each group are not necessarily
$ Arrnew [0] = array (
array('id' => 1,'user_name'=>'test1'),array('id' => 2,'user_name'=>'test2')
);
$ Arrnew [1] = array (
array('id' => 3,'user_name'=>'test3'),,array('id' => 4,'user_name'=>'test2')
);
$ Arrnew [2] = array (
Array (
'id' => 5,'user_name'=>'test3')
);
Array_chunk ($ arr, $ num); // $ num is 2 or 3
Check whether the following logic is correct.
$ Arr = array ('id' => 1, 'User _ name' => 'test1'), array ('id' => 2, 'user _ name' => 'test2'), array ('id' => 3, 'User _ name' => 'test3 '), array ('id' => 4, 'User _ name' => 'test2'), array ('id' => 5, 'user _ name' => 'test3'); rsort ($ arr); $ newArr = []; while (! Empty ($ arr) {$ count = rand (2, 3);/to control an array, set two or three elements. $ tmpArr = []; for ($ I = 0; $ I <$ count; $ I ++) {$ tmpArr [] = array_pop ($ arr) ;}$ newArr [] = $ tmpArr ;} dump ($ newArr );