Create array range
Creates a array with an range from, to
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function array_range($from, $to, $step=1){
$array = array();
for ($x=$from; $x <= $to; $x += $step){
$array[] = $x;
}
return $array;
}
print_r(array_range(0, 20, 5));
/*
returns:
Array
(
[0] => 0
[1] => 5
[2] => 10
[3] => 15
[4] => 20
)
*/
X
Url: http://www.jonasjohn.de/snippets/php/array-range.htm
Language: PHP | User: ShareMySnippets | Created: Oct 16, 2013