This article mainly introduces PHP simple implementation of two-dimensional array of matrix transpose operation, involving PHP for two-dimensional array traversal and operation skills, the need for friends can refer to the next
Specific as follows:
<?php $arr 1 = Array (array (), array (4,5,6), Array ( 6,7,8), Array (' A ', ' B ', ' C ') ); Echo ' script home test result:<br><br> '; Echo ' Matrix transpose before:<br> '; for ($i =0; $i <count ($arr 1), $i + +) {for ($j =0; $j <count ($arr 1[$i]), $j + +) { echo $arr 1[$i] [$j]. ' '; } Echo ' <br> '; } Echo ' Matrix transpose after:<br> '; for ($i =0; $i <count ($arr 1); $i + +) { //Determine number of transpose columns for ($j =0; $j <count ($arr 1[$i]); $j + +) { //determine number of transpose lines $arr 2[$j] [$i] = $arr 1[$i] [$j]; Assign the value of "Row I, Column J" of Matrix 1 to the "line J of Row I"} for Matrix 2 ( $j =0; $j <count ($arr 2); $j + +) { //iterate over the array 2 for ($i =0, $i <count ($arr 2[$j]), $i + +) { echo $arr 2[$j] [$i]. ' '; } Echo ' <br> '; }? >
Run output:
Related recommendations:
PHP merges two sequential array cases
How PHP gets the specified column in the array (case)
PHP six ways to sort arrays