PHP two-dimensional array rectangle transpose instance
<?php //two-D array transpose //define a two-dimensional array $arr =array (Array (), Array (4,5,6)); Defines an array to place the transpose data $arr 1=array (); Traverse Echo before transpose "before transpose:"; for ($i =0; $i <count ($arr), $i + +) {for ($j =0; $j <count ($arr [$i]); $j + +) { echo $arr [$i]; } echo ""; } echo "Transpose before and after:"; Determine the number of lines after the appliance for ($j =0; $j <count ($arr [0]), $j + +) { $arr 1[$j]=array (); } for ($i =0; $i <count ($arr), $i + +) {for ($j =0; $j <count ($arr [$i]); $j + +) { $arr 1[$j] [$i]= $arr [$i] [$j]; echo $arr; } } Traverse after transpose: for ($k =0; $k <count ($arr 1); $k + +) {for ($l =0; $l
The above is the PHP two-dimensional array rectangle transpose instance code share content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!