SunQuest
 
       PHP
  Home arrow PHP arrow Page 5 - PHP Operators
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
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 Operators
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 18
    2007-10-31

    Table of Contents:
  • PHP Operators
  • Assignment Operators
  • Arithmetic Operators
  • Incremental Operators
  • Better by Comparison
  • Logical Operators

  • 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

    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

    PHP Operators - Better by Comparison


    (Page 5 of 6 )

    People love to compare things. Is this better than that? Are you fatter than me? Am I just as ugly as you are? Is Picard Greater than or Equal to Kirk? I'll tell you right now, Cisco was greater than Kirk and Picard combined. Deep Space 9 FTW.

    Well, in PHP you can compare all day long with the help of Comparison Operators. They allow you to compare two or more values and then have the program respond appropriately. We will cover these more during the upcoming tutorial on Statements, but here is how they look in code:


    <html>

    <body>


    <?php


    $my_name = “Mr. T”;


    if ( $my_name == “Mr. T”) {

    echo “Your name is really Mr. T? I pity you fool!”;

    }


    ?>


    </body>

    </html>

    In the above example, we assigned the value “Mr. T” to the variable $my_name. We then made a program that stated if the value of $my_name was indeed “Mr. T” then print “Your name is really Mr. T? I pity you fool!”. If the value of $my_name had been anything else, the line would not have printed.

    Note that we used the == to compare the value of $my_name to our criteria (Mr. T).

    In the following code we will use the not equal to operator (!=).


    <html>

    <body>


    <?php


    $my_name = “Charlie Brown”;


    if ( $my_name != “Mr. T”) {

    echo “Your name is not Mr. T? Then quit that jibba-jabba!”;

    }


    ?>


    </body>

    </html>

    The code above checks to see if the value of $my_name is “Mr. T”. Since it isn't, it prints out the line:

     

      You name is not Mr. T? Then quit that jibba-jabba!

    If the value had been “Mr. T”, then nothing would have occurred.

    If it is still a little confusing, have no fear. It'll be clear as mud after the next few tutorials.

    More PHP Articles
    More By James Payne


       · Hey thanks for taking the time to read my article on PHP Operators- I hope it was...
       · . . . but, if I remember Correctly, it's Sisko, not Cisco. And Archer is way...
       · I don't recall if it is in PHP4, but the === operator can be quite valuable.
       · Don't you need some backslashes and an ending quote?echo "<h1...
     

       

    PHP ARTICLES

    - Viewing and Editing Tasks for a Project Mana...
    - More on Private Methods with PHP 5 Member Vi...
    - Adding Tasks to a Project Management Applica...
    - Utilizing Private Methods with PHP 5 and Mem...
    - Making Changes in a Project Management Appli...
    - Defining Public and Protected Methods with M...
    - HTML for a Project Management Application
    - Using Subclasses and Accessors with Member V...
    - Implementing Internet Protocols with PHP
    - Project Management: The Application
    - Working with Private Properties to Protect P...
    - Protecting PHP 5 Class Data with Member Visi...
    - Setting Up a Web-based Image Hosting Service
    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery





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