i figured i'd add some more functionality to the myRange() functions below.
now you can, besides giving a $step parameter,
1. count backwards
2. count with letters
3. give whatever parameter you want, there's nothing (i know of) that will cause an endless loop (try a negative $step for the previous function....)
<?php
function myRange($num1, $num2, $step=1)
{
if (is_numeric($num1) && is_numeric($num2))
{
$step = ( abs($step)>0 ? abs($step) : 1 ); $dir = ($num1<=$num2 ? 1 : -1); for($i = (float)$num1; $i*$dir <= $num2*$dir; $i += $step*$dir)
{
$temp[] = $i;
}
}
else
{
$num1=ord((string)$num1); $num2=ord((string)$num2);
$step = ( abs($step)>0 ? abs($step) : 1 ); $dir = ($num1<=$num2 ? 1 : -1); for($i = $num1; $i*$dir <= $num2*$dir; $i += $step*$dir)
{
$temp[] = chr($i);
}
}
return $temp;
}
print_r(myRange( 1, 3, 0.5 )); print_r(myRange( "a", "k", 3 )); print_r(myRange( "5", "9" )); print_r(myRange( "!", "%", 1/pi() )); ?>