PHP Program to find Matrix Transpose

You are Here:

Find Matrix Transpose

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


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>"; } ?>


Hi Developers, we almost covered 90% of String functions and Interview Question on PHP with examples for quick and easy learning.

We are working to cover every Single Concept in PHP.

Please do google search for:

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