helo frds i am new in php .please tel me how to perform matrix additon <?php echo "enter the number"; for(int i=0;int i<=2;int i++) { for(int j=0;int j<=2;int j++) { echo "enter the number" $a[j]; } echo "\n"; } ?> here i am not getting how to get the matrin values thanks
Should be like this for($i=0;$i<=2;$i++) { for($j=0;$j<=2;$j++) { echo "enter the number $i$j<br>"; } } Code (markup):
You cant get the input directly from the user like c,c++ or java... You should get the user input using html form controls... <form action="" method="post"> Enter the value : <input type="text" name="input"> You can get from the PHP like this <?php $input=$_POST['input'];
Should work fine on console (which I assume you are using since you original code was using \n for newlines): <?php $matrix = array(); for ($i=0; $i <= 2; $i++) { for ($j=0; $j <= 2; $j++) { echo PHP_EOL . "Enter the number for [$i][$j]:"; $line = fgets(STDIN); $matrix[$i][$j] = trim($line); } } Code (markup):