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.

TABLE OF CONTENTS:
  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
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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:


<html>

<body>


<?php


$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!';


else

{

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

}

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

?>


</body>

</html>

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
   

PHP ARTICLES

- 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...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap

Dev Shed Tutorial Topics: