Site Meter Web Dev Notes » Blog Archive » The FOREACH Loop Love Affair with Mr. Array

The FOREACH Loop Love Affair with Mr. Array

by

Remember our good friend the array? Well one thing I forgot to mention about Mr. Array is that he is in an eternal love affair with Mrs. FOREACH Loop. I know this site is normally about web development, but some gossip about our function friends is always important. In fact, when beginning development on any new site, you should always create personnas to be representative of your users to make sure you are really addressing their needs! I’ll talk more about personas another day though, for now les get back to our lovers quarrel…!

Mrs. FOREACH Loop (yes, you need to yell FOREACH really loud, then say Loop quietly, that’s how it’s spelled and as developers we need to follow standards!) is not like our other loop friends , the incredible FOR loop and the magical WHILE loop. Mrs. FOREACH Loop does not have a statement that runs alongside a counter that continues until the statement is proven false. The FOREACH Loop continues until it has used all values contained within an array. Some might say that Mrs. FOREACH Loop is therefore a bit of a gold digger… !

It’s a pretty simple concept. If the array contains one million items, the FOREACH loop will execute one million times. Here is an example of what a FOREACH Loop looks like:

<?php
   $MrArray = array(1, 2, 3, 5, 8);
   foreach ($MrArray as $MyLove)
   {
      print $MyLove . "\n";
   }
?>

In the above example, Mrs. FOREACH Loop prints all of Mr. Arrays numbers! Don’t they make a cute couple?

If you’ve got any dirt on any other PHP functions, please do not hesitate to report your finding immediately. I’d love to get some screenshots up of Mr. Array and Mrs. FOREACH at the bar or something… :)


3 Responses to “The FOREACH Loop Love Affair with Mr. Array”

  1. Web Dev Notes » Blog Archive » Introducing the different PHP Loops Says:

    [...] FOREACH Loops [...]

  2. Web Dev Notes » Blog Archive » Using Persona's During Development Says:

    [...] Persona’s During Development May 31st, 2007 by Deceth A few days ago I mentioned persona’s and promised to go into more details on a future date. Today, I am happy to announce that we have [...]

  3. Web Dev Notes » Blog Archive » How to Create Websites with PHP Says:

    [...] The FOREACH Loop Love Affair with Mr.Array [...]

Leave a Reply


About Web Dev Notes

Your one stop destination for anything and everything related to web development

Web Dev Notes Author(s)

Blogging Flair

New Media, Web 2.0 Channel Posts

  • 10 Ways to Make Sure Your SEO Goes Out of Its Way for You
    If they want to have success, companies should do everything they can to ensure that their SEO firm doesn't provide lousy service. Here are 10 tips to keep in mind: 1. Be realistic. Don't waste your [...]
  • Podcasting Transcription
    A Guest Post from Tishia Lee of Tishia Saves Time: When I first started offering transcription services as part of my Virtual Assistant business, transcribing podcasts was not something I [...]
  • Don't Dabble - Make A Commitment
    If you want to get the best bang for your buck, plan on podcasting for the long haul. Podcasters who “test” things out with one or two podcasts and then give up may think that they've given [...]
  • A Question of Podcasting Frequency
    This follows up on yesterday's post about not dabbling in podcasting but rather to make a commitment. Podcasting on a schedule is important when building a community and an audience. Don’t have [...]
  • Do You Twitter About Your Podcast?
    Whenever I release a new episode of Work at Home Moms Talk Radio is pop the link up on my Twitter and invite my followers to come check it out. This has brought me several first time listeners which [...]
  • Looking for Podcast Outsourcing?
    I mentioned having my podcast audio's transcribed in my last post. In case you wonder - no, I do not transcribe them myself. (Shudder the thought - I did enough transcription to last a lifetime in [...]
  • Business Podcasting Benefit: Be An Industry Thought Leader
    I often ask people 'Why haven't you started your podcast yet?' and a common reply is 'I don't feel like I'm enough of an expert to cover the topic I'm interested in.' Enough of an expert? [...]
  • Business Podcasting Benefit: More Content
    Building a business on the web requires that you generate a lot of content. Content on your website draws traffic both through search engines (people searching for your content) and through links [...]
  • Business Podcasting Benefit: Deeper Relationships
    A website visitor is just a website visitor. You can't really say that you have a relationship with someone who has only visited your website can you? But when the web visitor subscribes to [...]
  • Business Podcasting Benefit: Increased Market Exposure
    When you consider how many millions of people are walking around with iPods and other Mp3 players you have to wonder, wouldn't it be awesome if they came looking for you? Well they do. Ipod [...]

Hot Off The Press