Get Website Learn Coding Tech Story

PHP Programming Examples

<!DOCTYPE html>
<html>
	<head>
	</head>
	<body>
		<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
			<input type="text" name="length" placeholder="Length of the Fibonacci Series" />
			<input type="submit" />
		</form>
		<?php
			if(isset($_POST['length'])) {
				if(is_numeric($_POST['length'])) {
					$a = 0;
					$b = 1;
					echo "<br /> Fibonacci Series:<br /> 0";
					
					/* Loop the process using "While Loop" */
					while($b <= $_POST['length']) {
						echo " ".$b;
						$temp = $a + $b;
						$a = $b;
						$b = $temp;
					}
				}
			}
		?>
	</body>
</html>


          /****** Output ******/
          

Input:

20

Fibonacci Series:

0 1 1 2 3 5 8 13

Learn more about isset and is_numeric