PHP Challenge 1 - Generate the Fibonacci Numbers Based on User Input

phplogo.jpg

In this challenge you are required to allow the user to input a number. You will then use this number to generate the Fibonacci numbers.

The Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, ...etc

The next number in the sequence is found by adding the 2 previous numbers.

e.g. the 5th number in the sequence is 3 and is found by adding the 2 previous numbers together i.e. 1 + 2 = 3.

Develop a simple HTML form to allow the user to enter a number to represent the number of Fibonacci numbers to find.

Then develop a PHP script to echo out these Fibonacci numbers as a list separated by commas.

e.g. if the user enters 5 then the output needs to be:

0, 1, 1, 2, 3

NOTE: does your list have a trailing comma? (i.e. a comma at the end of the list).  If so, can you find a way to remove this?

Would you like the solution to this challenge?

The full video solution together with downloadable code is available in the PHP for Beginners course.

This course is taught by Patrick Morrow, a national award-winning teacher, who is very active in the course and who provides full support.

To enrol in the course click here.