The example in this article describes the PHP implementation of converting a one-dimensional array into a two-dimensional array composed of three consecutive values. Share it with everyone for your reference, the details 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); ?>
The running results are as follows:
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 ) )
Key code:
$bbb[] = array_slice($aaa, $i * 3 ,3); //3为3个一组,如果是2为2个一组
Readers who are interested in more PHP-related content can check out the special topic of this site: "PHP "Comprehensive array (Array) operation skills", "php sorting algorithm summary", "PHP common traversal algorithms and techniques summary", "PHP data structure and algorithm tutorial", "php programming algorithm summary", "PHP mathematical operation skills summary" , "Summary of usage of PHP regular expressions", "Summary of usage of PHP operations and operators", "Summary of usage of PHP string (string)" and "Summary of common PHP database operation skills"
I hope that what this article describes will help everyone in PHP programming. Helps.
The above introduces how PHP converts a one-dimensional array into a two-dimensional array composed of three consecutive values, including two-dimensional arrays and PHP content. I hope it will be helpful to friends who are interested in PHP tutorials.