Programming Basics

  Home arrow Programming Basics arrow Page 4 - A Tour of Decision Making Structures i...
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

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    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

    blog comments powered by Disqus

    PROGRAMMING BASICS ARTICLES

    - Control Flow Constructs
    - More Time Manipulation with PHP
    - Validating and Manipulating Dates with PHP
    - Using the Date Constructor in PHP
    - Calendar Construction with PHP
    - PHP`s Calendar Package
    - Getting Modified Versions and Correct Dates ...
    - Combining Date Functions in PHP
    - Using PHP for Date and Time in Programming
    - More Exception Handling with PHP
    - Exception Handling in PHP
    - Error Logging and Handling Exceptions
    - Configuration Directives for Error and Excep...
    - Error and Exception Handling
    - Python Modules for Games


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