Using a loop to build 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
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Using a loop to build an array?

Post by GeXus »

How would I use a loop that would build out an array, with the count of the loop being added to the array each time?

ex... the loop goes 5 times, i want array(1, 2, 3, 4, 5) in a variable....

Thanks!
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

You don't! :P

You just do:

Code: Select all

$arr = range(1, 5);
:wink:
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

Oren wrote:You don't! :P

You just do:

Code: Select all

$arr = range(1, 5);
:wink:

LOL... thank you!
Post Reply