neben der matrix in php

Ich versuche zu tun, matrix-addition in php. Hier bin ich versucht zu bekommen, die von den Eingaben des Benutzers und stellen Sie das Feld für die addition. Ich habe versucht, diese. ich habe einige Fehler hier. jeder kann die Lösung für dieses... Danke im Voraus...

<html>
<body>
<form name="form1" action="matrixaddjs.php" method="post">
Enter the number of rows for matrix : <input type="text" name="ar">
Enter the number of columns for matrix : <input type="text" name="ac">
<input type="submit" name="submit" value="submit">
<script>
var row=document.getElementById('ar').value;
var col=document.getElementById('ac').value;
var i;
var j;
var k;
var l;
var amatrix= new array();
document.write('<table>');
for(i=0;i<row;i++)
{
    amatrix[i]=new array(j);
            document.write('Enter the A matrix :'); 
    document.write('<tr>');
    for(j=0;j<col;j++)
    {
        document.write('<td>');
        document.write('<input type="text" name="amatrix[i][j]">');
        document.write('</td>');
    }
document.write('</tr>');
}
document.write('</table>');


var bmatrix= new array();
    document.write('Enter the B matrix :');
document.write('<table>');
for(i=0;i<row;i++)
{
    bmatrix[i]=new array(j);
    document.write('<tr>');
    for(j=0;j<col;j++)
    {
        document.write('<td>');
        document.write('<input type="text" name="bmatrix[i][j]">');
        document.write('</td>');
    }
document.write('</tr>');
}
document.write('</table>');
</script>
</form>
<?php
if($_POST['submit']=== 'submit')
{
$amatrix=$_POST['amatrix'];
$bmatrix=$_POST['bmatrix'];
echo "<table>";
    echo "The resultant matrix is :";
for($m=0;$m<$ar;$m++)
{
    echo "<tr>";
    for($n=0;$n<$ac;$n++)
    {
        $cmatrix[$m][$n]=$amatrix[$m][$n]+$bmatrix[$m][$n];
        echo "<td>";
        echo $cmatrix[$m][$n];
        echo "</td>";
    }
    echo "</tr>";

}
echo "</table>";
}
?>

</body>
</html>

wenn user gibt:

Geben Sie die Anzahl der Zeilen für matrix : 2

Geben Sie die Anzahl der Spalten für die matrix : 2

Geben Sie die matrix :

2 4

3 5

Geben Sie die matrix B :

3 4

5 6

Die resultierende matrix ist:

5 8

8 11

Dies ist mein erwartetes Ergebnis.

  • lassen Sie mich-code für Sie, für diese situation! aber Lesen Sie bitte jquery als gut b/c ist es einfach zu arbeiten mit jquery!
InformationsquelleAutor CJ Ramki | 2013-08-07
Schreibe einen Kommentar