PHP two-dimensional array Rectangular transpose instance
<?php
//Two D array transpose
//defines a two-dimensional array
$arr =array (Array (1,2,3), Array (4,5,6));
Defines an array to place the data of the transpose
$arr 1=array ();
Before
the transpose, iterate the echo "transpose before:<br/>";
For ($i =0 $i <count ($arr); $i + +) {for
($j =0; $j <count ($arr [$i]); $j + +) {
echo $arr [$i] [$j];
}
echo "<br/>";
}
echo "transpose before and after:<br/>";
Determine the number of rows 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;
}
}
After the transpose traversal: for
($k =0 $k <count ($arr 1), $k + +) {for
($l =0; $l <count ($arr 1[$k]); $l + +) {
echo $arr 1[$k [$l];
}
echo "<br/>";
>
The above PHP two-dimensional array rectangular Transpose example is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.