Easy To Learning
  • Login
  • Sign Up
  • Q&A
  • Home
  • Php Tutorial
  • MySql Tutorial
  • Object-Oriented Programming
  • Java Tutorial
  • HTML Tutorial
  • React JS Tutorials
  • Free Projects
  • Others
    • About Us
    • Contact Us
Fibonacci Series
Easy To Learning

Education Needs Complete Solution

Online Ask Question Question And Answer
  1. Home
  2. PHP Tutorials
  3. Fibonacci Series

PHP Tutorial

Basic PHP Fundamentals

  • PHP Tutorial Content
  • PHP Introduction
  • PHP History
  • Uses of PHP
  • PHP Features
  • What Is PHP
  • PHP Installation And Software Requirements
  • How To Install Wamp Server
  • How To Install Xampp Server
  • Php Syntax
  • PHP Variables
  • PHP Data Types
  • PHP Constants
  • PHP Echo And Print
  • PHP Operators
  • PHP Assignment Operators
  • PHP String And Logical Operators
  • Operators Categories
  • PHP Comments
  • PHP $ And $$ Variables
  • Super Global Variables

PHP Control Statement

  • PHP Control Structure
  • PHP If Statement
  • If Elseif Statement In PHP
  • Switch Statement In PHP
  • Break Statement In PHP
  • If Elseif Else Statement
  • Continue Statement In PHP

Php Loops

  • What Is Loop
  • For Loop In PHP
  • PHP Foreach Loop
  • PHP While Loop
  • Do While Loop

PHP Arrays

  • PHP Arrays
  • Indexed Arrays
  • Associative Array
  • Multidimensional Arrays
  • Array Functions
  • Array Constants
  • List of Array Functions
  • Array Functions First Exercise

Php String

  • String In PHP
  • PHP String Functions

PHP Functions

  • PHP Functions
  • PHP Parameterized Function
  • PHP Call By Value
  • Call By Reference In PHP
  • Default Argument Values Function In PHP
  • Variable Argument Function In PHP
  • Recursive Function In PHP
  • Math Function In PHP
  • Math Function Examples

PHP Form

  • Form Handling In PHP

PHP Include

  • Include File In PHP

PHP State Management

  • Cookies In PHP
  • Session In PHP

PHP File System

  • File Handling In PHP
  • Open Files In PHP
  • Read Files In PHP
  • Write Files In PHP
  • Delete Files In PHP
  • Append To Files In PHP

PHP Upload & Download

  • File Upload In PHP
  • Download File In PHP

PHP Mail System

  • Mail System In PHP
  • Mail With Attachment In PHP

Basic PHP Program

  • Php Programs
  • Sum Of Digits
  • PHP Even Odd Program
  • Prime Number Program
  • Table Of Number Program
  • Factorial Of A Number
  • Armstrong Number
  • Palindrome Number
  • Fibonacci Series

Fibonacci Series

Fibonacci Series Program in PHP

Fibonacci series is set as a sequence of numbers in which the first two numbers are 0 and 1, depending on the selected beginning point of the sequence, and each subsequent number is the sum of the previous two number. So, in this series, the nth term is the sum of (n-1)th term and (n-2)th term.

Fibonacci Series Logic:

  • Initializing number.
  • the nth term is the sum of (n-1)th term and (n-2)th term
  • Call Same Function Until Origin Condition


Example 1: How To Program Fibonacci series Using Recursive Function (Using For Loop)

Recursion is a method where we repeatedly call the same function until a origin condition is matched to end the recursion.

 

<?php   
// PHP code to get the Fibonacci series 
// Get fibonacci series Using Recursive function . 
function fibonacciSeries($number){ 
    // if and else if to generate first two numbers 
    if ($number == 0){
        return 0;   
    }else if ($number == 1){
        return 1;     
    }else{
        // Recursive Call to get the upcoming numbers
        return (fibonacciSeries($number-1) + fibonacciSeries($number-2));
    }
}  
// Main Program Call 
$number = 20; 
for ($counter = 0; $counter < $number; $counter++){   
    echo fibonacciSeries($counter),' '; 
} 
?> 


Output:

0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181

 

Example 2: Using the iterative method (Using While Loop)

we define the first and second number to 0 and 1 as fixed value. Following this, we display the first and second number. Then we send the flow to the iterative while loop where we get the next number by adding the previous two number and simultaneously we swap the first number with the second and the second with the third.

<?php 
// PHP code to get the Fibonacci series 
function fibonacciSeries($numnar){ 
    $numnar1 = 0; 
    $numnar2 = 1; 
    $count = 0; 
    while ($count < $numnar){ 
        echo ' '.$numnar1; 
        $numnar3 = $numnar2 + $numnar1; 
        $numnar1 = $numnar2; 
        $numnar2 = $numnar3; 
        $count++; 
    } 
} 
  
// Call Driver Code 
$numnar = 20; 
fibonacciSeries($numnar); 
?> 


Output:

0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181

 

Free Download Projects
Previous Chapter
Next Chapter

Ask a Question

Have a coding query or doubt? Ask here and get help from our community.

500 characters remaining
Submitting...
Free Download Projects
Join Telegram Group Join WhatsApp Group

Related Topics:
Fibonacci series without using recursion and using recursion

Member Sign In

Forgot?
Signing in...

Don't have an account? Register here

Create Free Account

Register Captcha
Registering...

Already have an account? Sign In

Ask a Question

500 characters remaining
Submitting...

About Easy To Learning

Easy To Learning is a comprehensive programming learning portal offering free, practical, developer-driven tutorials for PHP, Java, Python, Spring, MySQL, CSS, Bootstrap, CakePHP, and more.

Explore community-contributed questions and answers, and download ready-to-run source code projects.

Quick Links

  • Home
  • Questions & Answers
  • Download Projects
  • Blog & Articles
  • Member Login

Community

  • Telegram Group
  • WhatsApp Community
  • Ask a Question
  • Join as Member

Connect With Us

Stay updated with our newest programming tutorials and free open source projects.

© 2026 Easy To Learning. All Rights Reserved.