PHP
  Home arrow PHP arrow Page 9 - PHP 101 (part 3) - Chocolate Fudge And Time Machines
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 101 (part 3) - Chocolate Fudge And Time Machines
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2000-08-15


    Table of Contents:
  • PHP 101 (part 3) - Chocolate Fudge And Time Machines
  • Back To The Future
  • Revisiting The Past
  • Doing It By The Numbers
  • Anyone For Apple Pie?
  • The Generation Gap
  • What's That Noise?
  • Checking The Boxes
  • Miscellaneous Notes

  • 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 101 (part 3) - Chocolate Fudge And Time Machines - Miscellaneous Notes
    ( Page 9 of 9 )

    The auto-increment and auto-decrement operators
    --------------------------------------------------------------

    In our explanation of the "for" loop above, we mentioned the auto-increment operator [++] in passing. The auto-increment operator is a PHP operator designed to automatically increment the value of the variable it is attached to by 1.

    This snippet of code should explain it.


    <? // define $mercury as 10 $mercury = 10; // increment it $mercury++; // $mercury is now 11 echo $mercury; ?> Thus, $mercury++; is functionally equivalent to $mercury = $mercury + 1;
    And there's also a corresponding auto-decrement operator [--], which does exactly the opposite:

    <? // define $mercury as 10 $mercury = 10; // decrement it $mercury--; // $mercury is now 9 echo $mercury; ?>
    These operators are frequently used in loops to automatically update the value of the loop counter.

    break and continue
    -------------------------

    When dealing with loops, there are two important keywords you should be aware of: "break" and "continue".

    The "break" keyword is used to exit a loop when it encounters an unexpected situation. A good example of this is the dreaded "division by zero" error - when dividing one number by another one[which keeps decreasing], it is advisable to check the divisor and use the "break" statement to exit the loop as soon as it becomes equal to zero.

    The "continue" keyword is used to skip a particular iteration of the loop and move to the next iteration immediately - it's demonstrated in the following example:


    <? for ($x=1; $x<=10; $x++) { if ($x == 7) { continue; } else { echo "$x <br>"; } } ?>
    In this case, PHP will print a string of numbers from 1 to 10 - however, when it hits 7, the "continue" statement will cause it to skip that particular iteration and go back to the top of the loop. So your string of numbers will not include 7 - try it and see for yourself.

    And that's all we have time for this week. We'll be back soon with more PHP 101, same time, same channel. Make sure you tune in!

     
     
    >>> More PHP Articles          >>> More By Vikram Vaswani and Harish Kamath, (c) Melonfire
     

       

    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 3 Hosted by Hostway
    Stay green...Green IT