Reputation: 5558
What's the fastest way to populate an array with the numbers 1-100 in PHP? I want to avoid doing something like this:
$numbers = '';
for($var i = 0; i <= 100; $i++) {
$numbers = $i . ',';
}
$numberArray = $numbers.split(',');
It seems long and tedious, is there a faster way?
Upvotes: 5
Views: 3522
Reputation: 32364
range()
would work well, but even with the loop, I'm not sure why you need to compose a string and split it - what's wrong with simply:
$numberArray = array();
for ($i = 0; $i < 100; $i++)
$numberArray[] = $i;
Upvotes: 8