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];
6
  • What should be your actual output? Commented Dec 15, 2018 at 21:03
  • I want the output to be an array of numbers like my example. So it counts to 1500 Commented Dec 15, 2018 at 21:05
  • 1
    What have you tried? Showing bad code is better than no code. Commented Dec 15, 2018 at 21:06
  • This is very simple solution at least show some code what did you do to achieve this? Commented Dec 15, 2018 at 21:08
  • No need for loops. Have a look at range(). Commented Dec 15, 2018 at 21:10

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.