Google Groups Home Help | Sign in
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
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


    Reply to author    Forward  
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.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google