Post by Qphoria » 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) ?

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by JNeuhoff » Sun Aug 09, 2009 8:42 pm

Why would you ever want to to use something like

Code: Select all

foreach ($pages as $pages)
It doesn't make sense at all to me!

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by Qphoria » Mon Aug 10, 2009 1:18 am

I don't. It was something Daniel used in 0.x that I changed... but I am seeing he uses it in 1.x now as well. So I was wondering why.

Take a look at any file in catalog/view/theme/default/template/product/*.tpl

They all have

Code: Select all

foreach ($sorts as $sorts) {

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Daniel » Mon Aug 10, 2009 7:03 am

you are right!

I only did it with a few names.

its hard when you have one var called page that gives the page number and another called pages that holds all the page numbers.

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm
Who is online

Users browsing this forum: Majestic-12 [Bot] and 15 guests