Re: [PHP] modifying within foreach

2009-06-23 Thread Martin Scotta
AddBrainHandler x-httpd-php5 .php On Tue, Jun 23, 2009 at 4:25 PM, Robert Cummings wrote: > Ashley Sheridan wrote: > >> On Tue, 2009-06-23 at 15:07 -0400, Eddie Drapkin wrote: >> >>> It's just foreach($foo as $key => &$item) { } >>> >>> You can't assign the key by reference >.> >>> >>> On Tue, Ju

Re: [PHP] modifying within foreach

2009-06-23 Thread Eddie Drapkin
It's just foreach($foo as $key => &$item) { } You can't assign the key by reference >.> On Tue, Jun 23, 2009 at 3:04 PM, Ashley Sheridan wrote: > On Tue, 2009-06-23 at 12:56 -0600, kirk.john...@zootweb.com wrote: >> Andres Gonzalez wrote on 06/23/2009 12:26:38 PM: >> >> > I want to modify $resul

Re: [PHP] modifying within foreach

2009-06-23 Thread Robert Cummings
Ashley Sheridan wrote: On Tue, 2009-06-23 at 15:07 -0400, Eddie Drapkin wrote: It's just foreach($foo as $key => &$item) { } You can't assign the key by reference >.> On Tue, Jun 23, 2009 at 3:04 PM, Ashley Sheridan wrote: On Tue, 2009-06-23 at 12:56 -0600, kirk.john...@zootweb.com wrote: An

Re: [PHP] modifying within foreach

2009-06-23 Thread Ashley Sheridan
On Tue, 2009-06-23 at 15:07 -0400, Eddie Drapkin wrote: > It's just foreach($foo as $key => &$item) { } > > You can't assign the key by reference >.> > > On Tue, Jun 23, 2009 at 3:04 PM, Ashley > Sheridan wrote: > > On Tue, 2009-06-23 at 12:56 -0600, kirk.john...@zootweb.com wrote: > >> Andres Go

Re: [PHP] modifying within foreach

2009-06-23 Thread Andres Gonzalez
Thanks guys--passing by reference solved my problem. I was not aware that the foreach statement works on a copy. This was explained in the online documentation. Duh!! Thanks again, -Andres Ashley Sheridan wrote: On Tue, 2009-06-23 at 12:56 -0600, kirk.john...@zootweb.com wrote: Andres

RE: [PHP] modifying within foreach

2009-06-23 Thread Daevid Vincent
} } Or something to that effect, I just wrote that freehand, but you should get the idea. http://daevid.com > -Original Message- > From: Andres Gonzalez [mailto:and...@packetstorm.com] > Sent: Tuesday, June 23, 2009 11:45 AM > Cc: php-general@lists.php.net > Subject: R

Re: [PHP] modifying within foreach

2009-06-23 Thread Ashley Sheridan
On Tue, 2009-06-23 at 12:56 -0600, kirk.john...@zootweb.com wrote: > Andres Gonzalez wrote on 06/23/2009 12:26:38 PM: > > > I want to modify $results within the foreach. In other words, > > during a given pass of this iteration, I want to delete some > > of the items based on particular condition

Re: [PHP] modifying within foreach

2009-06-23 Thread Kirk . Johnson
Andres Gonzalez wrote on 06/23/2009 12:26:38 PM: > I want to modify $results within the foreach. In other words, > during a given pass of this iteration, I want to delete some > of the items based on particular conditions. Then on the next > pass thru the foreach, I want $results to be the newer,

Re: [PHP] modifying within foreach

2009-06-23 Thread Andres Gonzalez
{ if ($item == 'foo') unset($results[$key]); } -Original Message- From: Andres Gonzalez [mailto:and...@packetstorm.com] Sent: Tuesday, June 23, 2009 11:27 AM To: php-general@lists.php.net Subject: [PHP] modifying within foreach In the following example: foreach ($results as $key =&

RE: [PHP] modifying within foreach

2009-06-23 Thread Daevid Vincent
foreach ($results as $key => $item) { if ($item == 'foo') unset($results[$key]); } > -Original Message- > From: Andres Gonzalez [mailto:and...@packetstorm.com] > Sent: Tuesday, June 23, 2009 11:27 AM > To: php-general@lists.php.net > Subject: [P

[PHP] modifying within foreach

2009-06-23 Thread Andres Gonzalez
In the following example: foreach ($results as $key => $item) { //bla bla bla -- unset some of the $items } I want to modify $results within the foreach. In other words, during a given pass of this iteration, I want to delete some of the items based on particular conditions. Then on the ne