RE: [PHP] [foreach] - is it proper to...

From: Date: Thu, 31 May 2012 17:09:58 +0000
Subject: RE: [PHP] [foreach] - is it proper to...
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-318052@lists.php.net to get a copy of this message
-----Original Message----- From: Tedd Sperling [mailto:tedd@sperling.com] Sent: Thursday, May 31, 2012 1:01 PM To: php-general General Cc: Tristan Subject: Re: [PHP] [foreach] - is it proper to... On May 31, 2012, at 12:48 PM, Tristan wrote: > I'm using Zend Studio and it had a suggestion that I do a foreach as > such > > foreach($entry as $entry){ > > } > > instead of > > foreach($entries as $entry){ > > } > > they both seem to work but, from a readability standpoint and just > makes more sense to me to use method 2. Is it bad practice to go with > the 1st method of coding or preferred? > > Thanks, T But don't forget, the first scenario would be bad coding practice; you are mutating the array $entry. It will become the last value of the array you are foreach'ing. $entry begins as an array, and ends as a string. As a result, I'd suggest to stay away from it. The second scenario, $ entries remains an array, and $entry a string. Thanks, Mike

« previous php.general (#318052) next »