SunQuest
 
       Programming Basics
  Home arrow Programming Basics arrow Page 4 - A Tour of Decision Making Structures in PHP
Try It Free
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
IBM® developerWorks
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? 
PROGRAMMING BASICS

A Tour of Decision Making Structures in PHP
By: bluephoenix
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2003-10-19

    Table of Contents:
  • A Tour of Decision Making Structures in PHP
  • Comparison Operators
  • IF Statements
  • SWITCH-CASE statements
  • Conclusion

  • 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
     
    Try It Free
     
    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

    A Tour of Decision Making Structures in PHP - SWITCH-CASE statements


    (Page 4 of 5 )

    As the ?: is an alternative to if-then statements, a switch-case statement provides a cleaner way to code lengthy if-elseif statements where each test checks the same variable.

    <?php
    $weather 
    "rain";
    echo 
    "The weather forecast calls for $weather. ";
    switch (
    $weather)
    {
      case 
    "snow":
        echo 
    "You'd better bundle up!&lt;br /&gt;";
        break;

      case 
    "rain":
        echo 
    "Be sure to bring an umbrella!&lt;br /&gt;";
        break;

      case 
    "wind":
        echo 
    "Take the day off and fly a kite!&lt;br /&gt;";
        break;

      default:
        echo 
    "Who knows what to expect?&lt;br /&gt;";
        break;
    }
    ?>

    The comparisons made between the variable in the switch and the values designated by the case keyword. The code block of each case is terminated with break. A default case can be used to designate a piece of code that will execute if no other cases return a true comparison.

    More Programming Basics Articles
    More By bluephoenix


       · Wow, This is so cheap even for newbies,now i gat ma grip on dem logical...
     

    PROGRAMMING BASICS ARTICLES

    - Loops and PHP Decision Making
    - Operators, Conditionals, and PHP Decision-Ma...
    - PHP Decision-Making
    - Coding
    - Server Statistics
    - Looping in PHP
    - Cookies in PHP
    - Working with text files
    - Beginning Object Oriented Programming in PHP
    - A Tour of Decision Making Structures in PHP
    - PHP Strings Primer
    - PHP Control Structures
    - Intro to Vim
    - Reading Directorys with PHP
    - An Overview of Arrays in PHP





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