Create a PHP file called echo_machine.php that expects two GET parameters, one c
ID: 640434 • Letter: C
Question
Create a PHP file called echo_machine.php that expects two GET parameters, one called number and one called what. GET parameter values are passed into the PHP via the URL of the Webpage.
the PHP variable $_GET["number"] will hold "10" and the PHP variable$_GET["what"] will hold "Hello" for the PHP script to use. For this assignment, the echo_machine.php script must take the what parameter value and echo it number times, separated by spaces and breaking onto a new HTML line after every 5 times. Try out the above script, giving it different values for number and what, to see the expected behavior of the script. It does not matter what the script does if one (or both) of the parameters is not supplied in the URL.
Hint: The parameter values are strings, therefore you will need to convert thenumber parameter value to an integer value before it can be used as a number. (Look for variable handling functions in the Function Reference section of the PHP manual).
can you please comment heavily so i can get a better understanding of what is going on
Explanation / Answer
<?php
//Code Begins Here
$number=$_GET['number']; //Receive the number parameter in a PHP Variable Called number
$value=$_GET['what']; //Receive the what parameter in a PHP variable Called value
$i=0; //This keeps a record of when to give a line break
$count=1; //This isto create a loop
while($count<=$number) //Start a loop from 1 to the number of times provided
{
echo $value.' '; //Echo the value and a space
$i++; //Also increment i
if($i==5) //If i equals 5
{
echo '<br />';//Give a line break
$i=0; //Also make 'i' default value to 0
}
}
//Code Ends
?>