PHP Questions Home

Categories

Arrays
Files
Forms
Functions
Images
MySQL
Numbers
Others
Strings
Website


PHP Functions

PHP Functions


More PHP

Top Questions
Ask a Question

How can I create an array of numbers easily?


If you want to create an array of consecutive numbers in PHP, then you can do it the long hand way...

<?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!



More arrays PHP Questions

How do I return all the values in an array?
I am not interested in the values in the arrays, how can I discard them?
How do I add to the beginning of an array and find the number of elements in it?
How can I sort an array keeping the correlation between the index and value?
How can I easily view all members of an array?