Programming Basics

  Home arrow Programming Basics arrow Page 2 - 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 - Comparison Operators


    (Page 2 of 5 )

    The following chart shows some common operators you may use in your programs.

    operator    comparison
    ------------------------------------------------
      x == y    checks if the value of x is equal to
                the value of y

      x != y    checks if the value of x is not
                equal to the value of y

      x < y     checks if the value of x is less
                than the value of y

      x > y     checks if the value of x is greater
                than the value of y

      x <= y    checks if the value of x is less
                than or equal to the value of y

      x >= y    checks if the value of x is greater
                than or equal to the value of y

    (a) && (b)  checks if the value of statement a
                and statement b evaluate to "true"

    (a) || (b)  checks if the value of statement a
                or statement b evaluate to "true"

    Let's apply that information to some example comparisons. Assuming $x holds the value 5, $y holds 100 and $z holds 500:

    ($x == $y) && ($x <= $z)
    (5 == 100) && (5 <= 500)
       false   &&    true
    >  false

    ($x * $y) == $z
    (5 * 100) == 500
       500    == 500
    >  true

    ($x != $y) || ($y == $z)
    (5 != 100) || (100 == 500)
       true    ||    false
    >  true

    Be sure that you don't confuse = with ==. = assigns a value to a variable while == compares for equality. This can be a source of great frustration for many new programmers until they become more accustomed to working with them.

    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 9 - Follow our Sitemap