How can I create an array of numbers easily?
<?php
$myarray = array(1,2,3,4,5,6,7);
?>
Or you can do it the easy way, using the range function, which you simply pass the first and last value in the consecutive range. So this is equivalent to the above code:
<?php
$myarray = range(1,7);
?>
... and when you want an array containing the numbers 1 to a 1,000 - then you'll be glad you learned about this function!
Comment on this Question and Answer >>>
ASK A QUESTION
More arrays PHP Questions
I'm shuffeling through numbers range(1, 10). Can I eval resulting random numbers and convert to appropriate text? 1 = username1, 2 = username2...etc?How do I turn an array into a string?
How do I find if a value is already in an array or not?
How do I remove and view the last element of an array?
How can I display values in a two dimensional array?
