Select part of an array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Select part of an array

Post 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
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

foreach(array_slice($thearray, 0, 25) as $foo){
...
}
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Works a treat. Never spotted that function in the manual.

Thanks for fast reply!
Post Reply