foreach($blah as $blah) = Bad Practice?
Posted: Sat Aug 08, 2009 9:05 am
Although it is perfectly legal in PHP to use the same variable as the array and the individual value of a foreach loop. 1 major downside is that it then breaks that array for use further down the page.
I suppose it's not often that you'd use it multiple times in one page. Though one example would be pagination for example. Having it on top and bottom of a page for convenience, if you did foreach ($pages as $pages) then you wouldn't be able to use it after that.
Wouldn't it be best to always be sure to use foreach($pages as $page) ?
I suppose it's not often that you'd use it multiple times in one page. Though one example would be pagination for example. Having it on top and bottom of a page for convenience, if you did foreach ($pages as $pages) then you wouldn't be able to use it after that.
Wouldn't it be best to always be sure to use foreach($pages as $page) ?