If I have a variable $num = 50
how can I put the numbers 1-50 into an array?
This can be solved by using a simple for loop:
// Start ↓ End ↓ Step ↓
for ($i = 1; $i <= $num; ++$i) {
$array[] = $i;
}
I think the reason why range() wasn't accepted is that the array needed to start with 1; So:
$array=range(0,$num);
unset($array[0]);
Have a look at the documentation for the range() function:
<?php
$array = range(1, 50);
?>
Take a look at the range function.
$array = range(1, $num);