PHP
  Home arrow PHP arrow Page 7 - 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 - What's That Noise?
    ( Page 7 of 9 )

    Of course, there is a simpler way of extracting all the elements of an array - PHP4 has a "foreach" loop designed specifically for this purpose and similar in syntax to the Perl construct of the same name. Here's what it looks like:


    foreach ($array as $temp) { do this! }
    or, in English, "take each element of the array variable $array, place it in the variable $temp, and execute the set of statements within the curly braces on $temp"

    Let's demonstrate this by re-writing the example above in terms of the "foreach" loop:

    <html> <head> <basefont face="Arial"> </head> <body> <? // define some array variables $then = array("The Beatles", "Roy Orbison", "Frank Sinatra"); $now = array("Britney Spears", "N-Sync", "Jennifer Lopez", "Blink 182"); ?> While Mom and Dad listen to <? // use loop to extract and display array elements foreach ($then as $artist) { echo $artist . ", "; } ?> in the living room, I'm grooving to <? foreach ($now as $artist) { echo $artist . ", "; } ?> in the basement! </body> </html>


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