Fibonacci Series

Write a program to find the fibonacci series in php.

In Fibonacci series each number is the sum of the preceding ones.

Eg:- 0 1 1 2 3 5 8 13 121
start with 0 and 1, then
0+1 = 1, 1+1 = 2, 1+2 = 3, so on

Program :

<?php  
$num = 0;  
$num1 = 0;  
$num2 = 1;  
echo $num1.' '.$num2.' ';  
while ($num < 10 )  
{  
    $num3 = $num2 + $num1;  
    echo $num3.' ';  
    $num1 = $num2;  
    $num2 = $num3;  
    $num = $num + 1;  
}
?>  
  1. Define $num = 0, $num1 = 0, $num2 = 1.
  2. Print $num1 and $num2 as these are the starting numbers
  3. In while loop, 10 is the limit
  4. Add $num1 and $num2 and store to $num3
  5. Print $num3 as it is the next number
  6. Now we have to do the swapping, that means $num1 assigned with value of $num2, $num3 is assigned to $num2.
  7. Then $num incremented by 1

For more details about Fibonacci series click here

For other PHP Programs please click here

Related Posts

forest fire

Forest Fire – Techgig, All testcases passed. Challenge #1

Forest FireĀ (100 Marks) Challenge 1: Forest fire You are camping in a forest area at night. You are living with the forest officers to experience their challenges…

the magic wand

The Magic Wand – TechGig PHP answer, all test cases passed. Challenge #2

The Magic Wand – TechGig PHP answer – all testcases passed The Magic Wand (100 Marks) You are a wizard who possesses the magic wand that can be…

PHP interview Questions and Answers

What is PHP? Answer: PHP stands for Hypertext Preprocessor. It is a widely used server-side scripting language primarily designed for web development. PHP code is embedded within…

install php

A Step-by-Step Guide on How to Install PHP

Install PHP : A Step-by-Step Guide on How to Install PHP Introduction: PHP is a widely used server-side scripting language that powers countless websites and web applications….

what is php

What is PHP? Understanding PHP: The Powerhouse of Web Development

Introduction: What is PHP? Understanding PHP: The Powerhouse of Web Development: In the world of web development, PHP stands tall as one of the most widely-used and…

php form

Complete Php form example

Here we are going to check how to create a php form and insert its values to database table. In this example we will be submitting the…

This Post Has 4 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *