PHP 2D array rectangle transpose instance, 2D array rectangle
PHP two-dimensional array rectangular transpose instance
<? Php // transpose a two-dimensional array // defines a two-dimensional array $ arr = array (, 3), array (, 6 )); // define an array to hold transposed data $ arr1 = array (); // traverse echo before transpose: <br/> "; for ($ I = 0; $ I <count ($ arr); $ I ++) {for ($ j = 0; $ j <count ($ arr [$ I]); $ j ++) {echo $ arr [$ I] [$ j];} echo "<br/>";} echo "before and after transpose: <br/> "; // determine the number of rows after the device ($ j = 0; $ j <count ($ arr [0]); $ j ++) {$ arr1 [$ j] = array () ;}for ($ I = 0; $ I <count ($ arr); $ I ++) {for ($ j = 0; $ j <count ($ arr [$ I]); $ j ++) {$ arr1 [$ j] [$ I] = $ arr [$ I] [$ J]; // echo $ arr ;}// transpose traversal: for ($ k = 0; $ k <count ($ arr1); $ k ++) {for ($ l = 0; $ l <count ($ arr1 [$ k]); $ l ++) {echo $ arr1 [$ k] [$ l];} echo "<br/>" ;}?>
The above two-dimensional PHP array rectangular transpose example is all the content shared by the editor. I hope to give you a reference, and hope you can also support the help house.