PHP Program to find Matrix Transpose

Find Matrix Transpose

In the following example, we will transpose the given matrix (two-dimensional array).

Example

PHP Compiler
<?php $arr = array( array(1, 1, 1), array(2, 2, 2), array(3, 3, 3), ); echo "Matrix (3 x 3): <br>"; for($i=0; $i<3; $i++) { for($j=0; $j<3; $j++) echo $arr[$i][$j] . " "; echo "<br>"; } for($i=0; $i<3; $i++) { for($j=$i+1; $j<3; $j++) { $n = $arr[$i][$j]; $arr[$i][$j] = $arr[$j][$i]; $arr[$j][$i] = $n; } } echo "<br>Matrix Transpose: <br>"; for($i=0; $i<3; $i++) { for($j=0; $j<3; $j++) echo $arr[$i][$j] ." "; echo "<br>"; } ?>

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author