Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the fastest way to populate an array with numbers in PHP?

Tags:

arrays

php

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?

like image 211
Mr. Smith Avatar asked Nov 28 '22 06:11

Mr. Smith


1 Answers

The range function:

$var = range(0, 100);
like image 54
Jason246 Avatar answered Dec 24 '22 10:12

Jason246