<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$matrix1 = json_decode($_POST["matrix1"], true);
$matrix2 = json_decode($_POST["matrix2"], true);
$rows = count($matrix1);
$cols = count($matrix1[0]);
$result = [];
for ($i = 0; $i < $rows; $i++) {
for ($j = 0; $j < $cols; $j++) {
$result[$i][$j] = $matrix1[$i][$j] + $matrix2[$i][$j];
}
}
echo "Result: " . json_encode($result);
}
?>
<!DOCTYPE html>
<html>
<body>
<br>
<form method="post">
Matrix 1:
<input type="text" name="matrix1" placeholder='[[1,2],[3,4]]' required><br>
Matrix 2:
<input type="text" name="matrix2" placeholder='[[5,6],[7,8]]' required><br>
<input type="submit" value="Compute">
</form>
</body>
</html>