What is an Array Matrix in PHP?

What is an Array Matrix in PHP?

  • PHP
  • 1 min read

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).

Matrix in PHP

Here is a PHP program for displaying a 3*3(rows=3,cols=3) matrix in PHP:

echo "<b>The matrix is given below:-</b>"."<br>";
$a=array(array()); //declaration of a two dimensional array(here $a)
        echo $a[$i][$j];
    echo "<br>";


The matrix is given below:-

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.