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

What is the fastest way to populate an array with 1-100 digits in PHP? I want to avoid doing something like this:

$numbers = '';

for($var i = 0; i <= 100; $i++) {
    $numbers = $i . ',';
}

$numberArray = $numbers.split(',');

Seems long and tedious, is there a faster way?

+3
source share
2 answers

Function range:

$var = range(0, 100);
+22
source

range() will work well, but even with a loop I'm not sure why you need to compose a line and break it up - which is not so simple:

$numberArray = array();
for ($i = 0; $i < 100; $i++)
  $numberArray[] = $i;
+8
source

Source: https://habr.com/ru/post/1716787/


All Articles