Home arrow PHP arrow Page 7 - PHP 101 (part 3) - Chocolate Fudge And Time Machines

What's That Noise? - PHP

After teaching you the fundamentals of form processing, PHP 101 returns with an explanation of WHILE, FOR and FOREACH loops, those PHP constructs that can save you hours of unnecessary HTML coding. Also included: array variables, the auto-increment operator, and some yummy desserts.

TABLE OF CONTENTS:
  1. PHP 101 (part 3) - Chocolate Fudge And Time Machines
  2. Back To The Future
  3. Revisiting The Past
  4. Doing It By The Numbers
  5. Anyone For Apple Pie?
  6. The Generation Gap
  7. What's That Noise?
  8. Checking The Boxes
  9. Miscellaneous Notes
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 6
August 15, 2000

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: