Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Looping through arrays with foreach
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Richard Levasseur  
View profile  
 More options Mar 31 2006, 11:22 am
Newsgroups: comp.lang.php
From: "Richard Levasseur" <richard...@gmail.com>
Date: 31 Mar 2006 08:22:38 -0800
Local: Fri, Mar 31 2006 11:22 am
Subject: Re: Looping through arrays with foreach
It should be said that foreach operates on a copy of the array.
Changes to $value won't will not affect the original array.

With PHP5, the referential foreach was added, which aliases $value to
the original value in the array.
foreach($array as $key => & $value) { ... }
It should also be noted that $value will still exist as a reference
after the foreach() is over, thus assignments to $value will affect the
array also, so you much unset() it to prevent undesired side effects.

More information is available in the manual at:
http://us2.php.net/manual/en/control-structures.foreach.php


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.