This article mainly introduces PHP two-dimensional array of rectangular transpose example, interested in the friend's reference, I hope to help you.
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 "transpose before:<br/>" before transpose; for ($i =0; $i <count ($arr), $i + +) {for ($j =0; $j <count ($arr [$i]); $j + +) { echo $arr [$i]; } echo "<br/>"; } echo "transpose before and after:<br/>"; 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 <count ($arr 1[$k]), $l + +) { echo $arr 1[$k [$l]; } echo "<br/>"; }? >
Summary: The above is the entire content of this article, I hope to be able to help you learn.