Home arrow PHP arrow Page 4 - PHP Statements and Beginning Loops

Elseif - PHP

We discussed statements briefly in our last article and even got a sneak peek of an IF-statement. Sure I mean, the image was blurry, and the moment it saw us it ran off into the forest. But we saw it. Honest. So in this article, we're going to take a much closer look at PHP statements and even start learning about loops.

  1. PHP Statements and Beginning Loops
  2. If
  3. Else
  4. Elseif
  5. Here We Go Loop de Loop
  6. For Loop
By: James Payne
Rating: starstarstarstarstar / 5
November 05, 2007

print this article



That sounds like the name of a cow doesn't it? Good ole' Elseif just ain't makin' as much milk as she used to. But in fact, the Elseif statement does more than give milk. Elseif statements allow you to expand upon the Else statement. Just look at this table and it will be crystal clear:




$marry_who = "James";

if ( $marry_who == "James")


echo 'Now I am the both the Happiest and Fattest man alive!';


else if ($marry_who == "Brad")


echo 'Jennifer Aniston is prettier than you!';



echo 'Who the hell is he?!?';


echo 'I'm Brad Pitt's cousin, Fat Pitt.';




There, that's more like it. Now we are forcing the buxom Tomb Raider to choose between me and her lackluster actor boyfriend (I refuse to accept the fact that they are married). Even though in my mind I know who she would pick (and you better too you monkeys), let's look at the results of this program:

First we started off giving the variable $marry_who the value of "James." Then the program asks who she chose. Clearly, she chose me. And since the value of $marry_who is "James" the following prints out:

  Now I am both the Happiest and Fattest man alive!

  I'm Brad Pitt's cousin, Fat Pitt.

Tada. Now if by some crazy luck, the star's were aligned in Brad Pitt's favor, it would have printed this:

  Jennifer Aniston is prettier than you!

  I'm Brad Pitt's cousin, Fat Pitt.

And lastly, if Angelina has decided handsome, smart, funny, creatively brilliant men (me) and goofy, can't-act-his-way-out-of-a-paper-bag actors with a yawnable six-pack of abs (Brad Pitt) aren't her type, and she chooses some other fool, this would be there result:

  Who the hell is he?!?

  I'm Brad Pitt's cousin, Fatt Pitt.

Again, since the line about me being Brad Pitt's cousin is outside of the statement, it will print regardless of the IF...Else...Elseif result.

>>> More PHP Articles          >>> More By James Payne

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: