[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

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: [PHP] modifying within foreach

Re: [PHP] modifying within foreach

2009-06-23 Thread Andres Gonzalez
- 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 = $item) { //bla bla bla -- unset some of the $items } I want

Re: [PHP] modifying within foreach

2009-06-23 Thread Kirk . Johnson
Andres Gonzalez and...@packetstorm.com 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

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 and...@packetstorm.com 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

RE: [PHP] modifying within foreach

2009-06-23 Thread Daevid Vincent
://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: Re: [PHP] modifying within foreach I do not want to delete the whole array, only a particular $item. given this $results array

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:

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 Sheridana...@ashleysheridan.co.uk wrote: On Tue, 2009-06-23 at 12:56 -0600, kirk.john...@zootweb.com wrote:

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 Sheridana...@ashleysheridan.co.uk wrote: On Tue, 2009-06-23 at 12:56 -0600,

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 Sheridana...@ashleysheridan.co.uk wrote: On Tue, 2009-06-23 at 12:56 -0600, kirk.john...@zootweb.com wrote: Andres Gonzalez and...@packetstorm.com wrote on 06/23/2009

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 rob...@interjinn.comwrote: 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