Here’s an example of how you can create a matrix program in PHP:

<?php

// Define the matrix size
$rows = 3;
$cols = 3;

// Initialize the matrix
$matrix = array();
for ($i = 0; $i < $rows; $i++) {
  for ($j = 0; $j < $cols; $j++) {
    $matrix[$i][$j] = 0;
  }
}

// Fill the matrix with values
for ($i = 0; $i < $rows; $i++) {
  for ($j = 0; $j < $cols; $j++) {
    $matrix[$i][$j] = $i * $cols + $j + 1;
  }
}

// Print the matrix
for ($i = 0; $i < $rows; $i++) {
  for ($j = 0; $j < $cols; $j++) {
    echo $matrix[$i][$j] . " ";
  }
  echo PHP_EOL;
}

?>

This will create a 3×3 matrix with values from 1 to 9. You can change the $rows and $cols variables to define the size of the matrix, and modify the code in the for loops to fill the matrix with different values.

Leave a Reply

Your email address will not be published. Required fields are marked *

Upgrade PHP Version without using cPanel setting