<?php
define("NL", 7);
define("NC", 4);
$matriz = [];
echo "Preencha a matriz " . NL . "x" . NC . ":\n";
// Leitura dos valores da matriz
for ($i = 0; $i < NL; $i++) {
    for ($j = 0; $j < NC; $j++) {
        while(true) {
            echo "\nEntre com matriz[" . ($i + 1) . "][" . ($j + 1) . "]: ";
            $entrada = trim(fgets(STDIN));

            if (is_numeric($entrada)) {
                $matriz[$i][$j] = (float)$entrada;
                break;
            } else {
                echo "Entrada inválida. Por favor, digite um número.\n";
            }
        }
    }
}
for ($i = 0; $i < NL; $i++) {
    echo "\n|";
    for ($j = 0; $j < NC; $j++) {
        printf("%10.2f", $matriz[$i][$j]);
    }
    echo " |";
}
?>

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: