Programming Basics
  Home arrow Programming Basics arrow Page 2 - A Tour of Decision Making Structures in PHP
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 
JMSL Numerical Library 
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
     
     
    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


       · 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