PHP
  Home arrow PHP arrow Page 4 - PHP Statements and Beginning Loops
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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: starstarstarstarstar / 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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    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
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    Stay green...Green IT