Yes and no (in this case).

Yes, it'll be evaluated in each iteration and no, I don't think you'd
gain that much in this case because the evaluation would only take
place twice. Though I don't know how expensive array_slice vs.
creation of another variable and assigning a value to it is ....

But if you'd operate on large arrays it might make sense pulling the
eval out of the loop.

At least that's what I read in a tuning related article on zend.com

Richard


Friday, April 30, 2004, 8:37:10 AM, thus was written:
> Just a quick follow-up question on that:

> Curt Zirzow wrote:

>>foreach(array_slice($filenames, 0, 2) as $filename) {
>>  $files[] = "path/to/" . $filelname;
>>}
>>  
>>

> Will a function (such as the array_slice here) in a foreach statement
> get re-evaluated for each iteration, or is it evaluated just once?

> In other words, is there anyhing gained by doing:

> $short_array = array_slice($filenames, 0, 2);

> foreach($short_array as $filename) {
>   $files[] = "path/to/" . $filelname;
> }


> /Mattias
  

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to