Page 1 of 1

Using foreach loops

Posted: Mon Jun 06, 2005 2:11 am
by Stryks
Just wondering about calling the foreach function.

Lets say I have an array with repeated values and I wanted to run a loop for each individual version. I could do something like ...

Code: Select all

$arr_ing = array_unique($ing_list);
foreach($ing_list as $key=>$item) {
   // do something
}
... but I'm wondering if there are going to be problems with something like ...

Code: Select all

foreach(array_unique($ing_list) as $key=>$item) {
   // do something
}
I guess what I'm really worried about is that it will run the array_unique on each pass.

Any help would be great. Cheers

Re: Using foreach loops

Posted: Mon Jun 06, 2005 2:41 am
by patrikG
Stryks wrote:I guess what I'm really worried about is that it will run the array_unique on each pass.
Yup. And you only need to run it once.