[Solved] Numbers from 1 to N in PHP

  

3
Topic starter

You are given a number num. Write a PHP script that loops through all of the numbers from 1 to num and prints them. The input comes as a parameter named num. The parameter num will hold a positive integer.

Examples:

multphonum3
1 Answer
2

Here's the code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
</head>
<body>
<form>
    N: <input type="text" name="num"/>
    <input type="submit"/>
</form>
 
<?php
if (isset($_GET['num'])) {
    $num = $_GET['num'];
    for ($i = 1; $i <= $num; $i++) {
        echo $i." ";
    }
}
?>
 
</body>
</html>
Share: