Page 1 of 1

Select part of an array

Posted: Tue Apr 06, 2004 9:09 pm
by Chris Corbyn
Hi,

How do you only use say the first 25 elements of an array in a foreach loop?

There are hundreds of elements in my array but I only want to do things with the first 25 in the loop.

Thanks

Posted: Tue Apr 06, 2004 9:17 pm
by markl999
foreach(array_slice($thearray, 0, 25) as $foo){
...
}

Posted: Tue Apr 06, 2004 9:21 pm
by Chris Corbyn
Works a treat. Never spotted that function in the manual.

Thanks for fast reply!