Fibonacci Sequence in PHP

by Tyler Perroux on January 11, 2010

UPDATE: ADDED THREE NEW WAYS THAT YOU CAN DO THIS IN PHP.
IF YOU WANT TO SEE IT IN ACTION, CLICK HERE
Well I finally got it to work, and I felt that I should share this with the Open Source world.

Here it is, the Fibonacci Sequence coded in PHP.

If you are looking for some webhosting to practice with PHP, TylerPerroux.com recommends Bluehost.com

WARNING: THIS CAN CAUSE YOUR SERVER/COMPUTER TO CRASH IF USED INDIRECTLY. HOPEFULLY PHP WOULD CATCH THIS, AS THIS SCRIPT CAN CAUSE A NEAR ENDLESS LOOP. THERE IS NO WARRANTLY, EITHER IMPLIED OR EXPRESSED THAT THIS SCRIPT WORKS. ANY HARM THAT MAY HAPPEN BECAUSE OF THE IMPROPER/PROPER USE OF THIS SCRIPT IS IN NO WAY MY FAULT. FULL DISCLAIMER.

<?php
/**
* Example Fibonacci implementation to (n) steps (without recursion)
* @return array
@var $req - Array of Fibonacci numbers
*/
function fibonacci1( $steps = 10 )
{
list($current,$next,$curnum,$seq ) = array( 0, 1, 1, array() );

do
{
$curnum++;
$seq[] = $current;
$add   = $current + $next;
$current   = $next;
$next   = $add;
} while ( $curnum <= $steps );

return $seq;
}

// Example of first 15 Fibonacci numbers
echo "1) ";
print_r(fibonacci1(15));

echo "<br/>";
echo "2) ";

// This changes it from a multi-dimensional arry to a normal one.
foreach(fibonacci1(15) as $asdd => $asddd){
echo $asddd . " ";
}

function fibonacci2($n)
{
if($n == 0)
return 0;
elseif ($n == 1)
return 1;
else
return fibonacci2($n - 1) + fibonacci2($n - 2);
}
echo "<br>";
echo "3) ";

for($i = 0; $i < 15; $i++)
{
echo fibonacci2($i) . " ";
}
?>

<?php
/**
* The fibonacci function should look familiar.
*/
echo "<br>";

function fibonacci3($n){
$a = 0;
$b = 1;
for ($i = 0; $i < $n; $i++){
printf("%d\n",$a);
$sum = $a+$b;
$a = $b;
$b = $sum;
}
}echo "4) ";

fibonacci3(15);
echo "<br>";
show_source(__FILE__);
?>

Alright this explains everything.
1) This is a function that outputs a multi-dimensional array, without using recursion. $current_Number => $fibonacci_Num
2) Uses the same thing as 1, but cleans it up to only output the $fibonacci_Num
3) This uses recursion, and the base of it is a use of the explicit formula given.
4) This is just a simple for loop to output the numbers. Easy.

–Tyler Perroux

  • Share/Bookmark

{ 0 comments }

First Result on Google using 100% Organic SEO

by Tyler Perroux on December 15, 2009

Well of course this is nothing new. I bet you see those ad’s that show how you can be number one on Google, and you have to pay some unworldly price to get it.

Well this is your solution, using 100% Organic SEO, which is free, to promote your site or blog. Now organic means you don’t use pesticides, or things that just aren’t natural. Well that’s exatly what SEO is.

Now what is SEO, well it’s an acronym for Search Engine Optimization. The simplest way to describe it is how a human reads. People would rather see a site like mysite.com/products/free-seo, than something like mysite.com/?cat=2&id=28. People don’t like numbers and variables, they like plain and simple SEO.

Now if you don’t believe me on being the first result in Google, just use some of the links below, and you will see my site right up there as the first result.

godaddy domain subdomain with apacheKeyword 1
godaddy subdomain with apacheKeyword 2
total number of lines in a projectKeyword 3
home directory of Apache on godaddyKeyword 4
godaddy dns record subdomain apacheKeyword 5

Now most of these keywords have hundreds of millions of pages competing with me, but the reason why my pages are higher up than their’s, is because I have good content, and I market my post’s well.
Now this is pretty good, I am competing with industry leading website and corporations like GoDaddy, Wordpress.org, Ubuntu Forums, and Trap17.

If you would like to know how you can copy my same results, and be the first result in Google, just enter your name and email below. You will be receiving a nice email with some great SEO and marketing tips for you blog or website.

This is going to be fun =)
Tyler Perroux

  • Share/Bookmark

{ 1 comment }

Warrior Forum Mastermind Groups Project

December 12, 2009

Now not to say that I don’t currently love the forum style way of searching for groups, and trying to plan meetings, but I don’t.
Now I posted a thread over at the Warrior Forum a few weeks back entitled “Building Relationships with IM’s“.
Now out of the response from JMPruitt:
··· That would be a great idea [...]

Read the full article →

How to lose all your Twitter followers from ONE Post?

November 28, 2009

Now Twitter is a wonerful tool for Internet Marketers, and advertisers, but there is one thing that most people seem to forget, that Twitter is a Social Network, not an advertising billboard.
Now there is a wonderful thing about Twitter which can increase your conversion rates, and your relationships on Twitter called Direct Messaging(Private Messages).
Now this [...]

Read the full article →

$7 Dollar Offers

November 15, 2009

Now this website is quite amazing. The entire plan for the website is for people to sell smaller ebooks for a small price.
Some of the products on the site are free, like the Facebook Social Ads ebook.
The entire site is based on Jonathan Leger’s $7 Dollar Secrets.

This is like Clickbank, with cheaper products, and almost [...]

Read the full article →

Craigslist.org Clone Script

November 15, 2009

In honor of @Wasim from the WarriorForum, I have decided to reopen this project for the public domain.
The original project was named BowieList in honor of the BowieList.org site. I will be releasing another clean and updated version of this script under the new name, PerrouxList.
This script will be freely released on this site, under [...]

Read the full article →

Is the Rich Jerk a SCAM?

November 9, 2009

Watch the video below to see what The Rich Jerk is really about!!!

Read the full article →

Complete Project outline for x00n

November 9, 2009

DISCLAIMER: Use at your own risk. This is not set in stone, and is not the final draft or outline. Once the project is complete, nothing will be released, until testing is complete.
x00n Project Outline
Folder Outline
· ./install
a. Contains the installation files
· ./lib
a. Libraries, and other backend things.
· ./Sources
a. Source files for calls to the ?action=command
· ./torrents
a. More or less what the name says, [...]

Read the full article →

Free PTC Affiliate Marketing Course

November 4, 2009

Alright. This is the first that I am actually going to get going on how you can make money online.
Now I cannot lie, there are hundreds if not thousands of sites out there that are just there to take you money. After going through some of my own issues with these sites, I have found [...]

Read the full article →

Old promises, Now Coming in Good Faith

August 26, 2009

Well months and months ago, back when there was always time to run through code, lolly gagging in the amazing complexity of it, there was a dream to shoot our a brand new site, known as x00n.
Well short and sweet, that didn’t happen. I was trying to reuse old code(8[) using organization ideas from other [...]

Read the full article →