给定开始和结束值,再给定一个步进值,就可以生成一个等差数组
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 ) */