The running results are as follows:
<?php $aaa = array('aa','bb','cc','dd','ee','ff','gg','hh','ii'); for($i=0;$i<3;$i++) { $bbb[] = array_slice($aaa, $i * 3 ,3); } print_r($bbb); ?>
Key code:
Array ( [0] => Array ( [0] => aa [1] => bb [2] => cc ) [1] => Array ( [0] => dd [1] => ee [2] => ff ) [2] => Array ( [0] => gg [1] => hh [2] => ii ) )
Readers who are interested in more PHP-related content can check out the special topics on this site: "Complete PHP Array Operation Skills", "Summary of PHP Sorting Algorithms", "Summary of PHP Common Traversal Algorithms and Techniques", "PHP Data Structure and Algorithm Tutorial", "php Programming Algorithm Summary", "PHP Mathematical Operation Skills Summary", "php Regular Expression Usage Summary", "PHP Operations and Operator Usage Summary", "php String Usage Summary" 》and《Summary of common database operation skills in php》
$bbb[] = array_slice($aaa, $i * 3 ,3); //3为3个一组,如果是2为2个一组