Is it possible to store multiple textbox values in array, i have N number of textboxes
<input type="text" name="grade[]" id="grade" />
<input type="text" name="grade[]" id="grade" />
<input type="text" name="grade[]" id="grade" />
i tried this code to add all the text box value but it returns only the last text box value.
$grade=$_POST['grade'];
for($i=1;$i<=3;$i++)
{
$per=$grade[$i]*$grade[$i];
echo $per;
}
Besides of starting on 0, it should finish on 2 if you have 3 text boxes.
Or you could use the array length if you don’t want to hardcode the number of iteractions. This should work:
EDIT
This should work too and it’s slightly cleaner (avoiding the -1) and using the pow() function: