Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,945 questions

51,887 answers

573 users

How to create an array containing a range of numbers in PHP

4 Answers

0 votes
$arr_2_3_4 = range(2, 4);

print_r($arr_2_3_4);
     

     
/*

run:

Array ( [0] => 2 [1] => 3 [2] => 4 ) 

*/


answered Apr 21, 2014 by avibootz
edited May 24, 2015 by avibootz
0 votes
$rev_6_5_4_3 = range(6, 3);
print_r($rev_6_5_4_3); 
     

     
/*

run:

Array ( [0] => 6 [1] => 5 [2] => 4 [3] => 3 )  

*/


answered May 24, 2015 by avibootz
0 votes
$numbers = range(0, 10);
 
foreach ($numbers as $n)
    echo $n . "<br />";
      
     
/*

run:

0
1
2
3
4
5
6
7
8
9
10 

*/


answered May 24, 2015 by avibootz
0 votes
foreach (range(1, 13) as $number) 
{
    echo $number  . "<br />";
}
      
     
/*

run:

1
2
3
4
5
6
7
8
9
10
11
12
13

*/


answered May 24, 2015 by avibootz

Related questions

1 answer 100 views
1 answer 90 views
1 answer 81 views
1 answer 104 views
2 answers 105 views
...