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  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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: starstarstarstarstar / 19
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    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
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT