PHP
  Home arrow PHP arrow Page 4 - PHP Statements and Beginning Loops
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

PHP Statements and Beginning Loops
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 5
    2007-11-05

    Table of Contents:
  • PHP Statements and Beginning Loops
  • If
  • Else
  • Elseif
  • Here We Go Loop de Loop
  • For Loop

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    PHP Statements and Beginning Loops - Elseif
    (Page 4 of 6 )

    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


       · Hey thanks for stopping by. In this article I discuss conditional statements like...
       · On page 3:There's the following...
       · I enjoy your writing style and the subject matter but there are a few...
     

       

    PHP ARTICLES

    - Setting Up a Web-based Image Hosting Service
    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery
    - Using Timers to Benchmark PHP Applications
    - Benchmarking Applications with PHP
    - Setting Up a Web-Based File Manager: PHPfile...
    - Developing a Modular Class For a PHP File Up...
    - Setting Up a Web-Based File Manager: bfExplo...
    - Defining a Custom Function for File Uploader...
    - Parsing Child Nodes with the DOM XML extensi...
    - Creating an Error Handling Module for a PHP ...
    - Accessing Attributes and Cloning Nodes with ...
    - Retrieving Information on Selected Files wit...
    - Handling HTML Strings and Files with the DOM...
    - Building File Uploaders with PHP 5

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway