An array matrix in PHP can be a collection of numbers, strings, etc. arranged into a specific number of rows and columns. In PHP, the matrix can be created using a two-dimensional array(an array of arrays).
Here is a PHP program for displaying a 3*3(rows=3,cols=3) matrix in PHP:
<html> <body> <?php echo "<b>The matrix is given below:-</b>"."<br>"; $a=array(array()); //declaration of a two dimensional array(here $a) for($i=0;$i<3;$i=$i+1) { for($j=0;$j<3;$j=$j+1) { $a[$i][$j]=$i+$j; echo $a[$i][$j]; } echo "<br>"; } ?> </body> </html>
Output:
The matrix is given below:- 012 123 234
Here $a[$i][$j] is the array element with row index $i and column index $j. Each array element is containing here, a value through the statement $a[$i][$j]=$i+$j and values are displaying with echo $a[$i][$j] statement.