43. PHP Program to Print given name in N times.
How does this program work?
- In this program we are going to learn about how to print given name in N times using PHP.
- In this program we are using goto label in php and it is used to repeat the name n times in easy way.
Here is the code
<html>
<head>
<title>PHP Program To print a given name in N times</title>
</head>
<body>
<form method="post">
<table border="0">
<tr>
<td> <input type="text" name="name" value="" placeholder="Enter name"/> </td>
</tr>
<tr>
<td> <input type="text" name="num" value="" placeholder="Enter Number of times to repeat"/> </td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Submit"/> </td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$repeat = $_POST['num'];
echo "Given input :"; //To print given input
echo $name;
echo "Repeat times : ".$repeat."times";
//Counter initialization with 1
$count = 1;
//Defining lable
start:
echo $name;
$count++;
if($count<=$repeat)
goto start;
return 0;
}
?>
</body>
</html>