Re: re-keying an array

From: Date: Fri, 30 Apr 2004 07:36:20 +0000
Subject: Re: re-keying an array
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-185016@lists.php.net to get a copy of this message
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

« previous php.general (#185016) next »