51. PHP Program to Display 9 elements in 3x3 matrix format.
How does this program work?
- In this program we are going to learn about how to display 9 numbers in 3x3 matrix format using PHP.
- First 9 numbers can be stored in one variable using arrays.
- After that we can followed by the below logic then we get the Output in matrix format.
Here is the code
<html>
<head>
<title>PHP Program To display 9 elements in 3x3 matrix format</title>
</head>
<body>
<?php
// Elements of matrix a
$a= array( array(1, 0, 1), array(4, 5, 6), array(1, 2, 3) );
// To determine the no.of rows and columns of given matrix
$rows = count($a);
$cols = count($a[0]);
echo ("The 3*3 Matrix is: ");
// To print result in matrix form
for($i = 0; $i < $rows; $i++)
{
for($j = 0; $j < $cols; $j++)
{
echo ($a[$i][$j] . " ");
}
echo (" ");
}
return 0;
?>
</body>
</html>