Re: [PHP] re-keying an array

2004-05-04 Thread Jason Barnett
Justin Patrin wrote: Richard Harb wrote: Uh, I was wrong... Foreach evaluates only once at initialisation... You can even unset the array once into the loop and it still works perfectly well (not that I recommend this as good practice or whatever, just did some checking to be sure :) Richard That

Re: [PHP] re-keying an array

2004-04-30 Thread Mattias Thorslund
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

Re: [PHP] re-keying an array

2004-04-30 Thread Richard Harb
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

Re: [PHP] re-keying an array

2004-04-30 Thread Curt Zirzow
* Thus wrote Mattias Thorslund ([EMAIL PROTECTED]): 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: [PHP] re-keying an array

2004-04-30 Thread Richard Harb
Uh, I was wrong... Foreach evaluates only once at initialisation... You can even unset the array once into the loop and it still works perfectly well (not that I recommend this as good practice or whatever, just did some checking to be sure :) Richard Friday, April 30, 2004, 9:55:14 AM, thus

Re: [PHP] re-keying an array

2004-04-30 Thread Justin Patrin
Richard Harb wrote: Uh, I was wrong... Foreach evaluates only once at initialisation... You can even unset the array once into the loop and it still works perfectly well (not that I recommend this as good practice or whatever, just did some checking to be sure :) Richard That will work because

Re: [PHP] re-keying an array

2004-04-29 Thread Richard Harb
http://www.php.net/manual/en/function.array-values.php ? Richard Friday, April 30, 2004, 3:48:06 AM, thus was written: been RTFMing for about 10 minutes, and can't find the function to re-key an array. In other words, I want an array of items to remain in their current order, but have the

Re: [PHP] re-keying an array

2004-04-29 Thread John W. Holmes
Justin French wrote: been RTFMing for about 10 minutes, and can't find the function to re-key an array. In other words, I want an array of items to remain in their current order, but have the keys renumbered counting from zero. yes, I know it can be done with a foreach, but I was hoping for

Re: [PHP] re-keying an array

2004-04-29 Thread Justin French
On 30/04/2004, at 12:06 PM, John W. Holmes wrote: Although this begs the question of why you'd need to rekey an array... It seemed the easiest way to get the first two elements off the beginning of the array after shuffle()ing it, or so I thought -- but I'm more than happy to hear of a better

Re: [PHP] re-keying an array

2004-04-29 Thread John W. Holmes
Justin French wrote: On 30/04/2004, at 12:06 PM, John W. Holmes wrote: Although this begs the question of why you'd need to rekey an array... It seemed the easiest way to get the first two elements off the beginning of the array after shuffle()ing it, or so I thought -- but I'm more than happy

Re: [PHP] re-keying an array

2004-04-29 Thread Curt Zirzow
* Thus wrote Justin French ([EMAIL PROTECTED]): On 30/04/2004, at 12:06 PM, John W. Holmes wrote: Although this begs the question of why you'd need to rekey an array... It seemed the easiest way to get the first two elements off the beginning of the array after shuffle()ing it, or so I

Re: [PHP] re-keying an array

2004-04-29 Thread Curt Zirzow
* Thus wrote John W. Holmes ([EMAIL PROTECTED]): Justin French wrote: On 30/04/2004, at 12:06 PM, John W. Holmes wrote: Like I said, always happy to see something in a few less lines :) If I'm following what you want to do correctly: for($i=0;$i2;$i++) { $key =

Re: [PHP] re-keying an array

2004-04-29 Thread Justin French
On 30/04/2004, at 1:47 PM, Curt Zirzow wrote: foreach(array_slice($filenames, 0, 2) as $filename) { $files[] = path/to/ . $filelname; } Ahh array_slice() is EXACTLY what I was looking for :) --- Justin French http://indent.com.au -- PHP General Mailing List (http://www.php.net/) To