0

I have a variable like so:

$array = array();
$stock = 1500;

How can extract this number and add each number starting from 1 into $array.

For example:

$array = [1, 2, 3, 4, 5, 6, ..., 1500];
Qirel
  • 25,449
  • 7
  • 45
  • 62
Shaun
  • 757
  • 1
  • 8
  • 36

1 Answers1

4

All you need is range(). No need for any loops - a simple one-liner is all you need!

$stock = 1500;
$array = range(1, $stock);

https://3v4l.org/QbHIB

Qirel
  • 25,449
  • 7
  • 45
  • 62