note 42439 deleted from function.range by tomsommer
| From: | tomsommer@php.net | Date: | Mon, 17 May 2004 06:32:50 +0000 |
| Subject: | note 42439 deleted from function.range by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-69696@lists.php.net to get a copy of this message | ||
Note Submitter: Forrester@tfcustomized.com
----
For those with < PHP 5.0.0 and without a step feature, here's a little function I've
whipped up to allow you to use the step feature.
function myRange($low,$high,$step='1')
{
$ranArray = range($low,$high);
$step = $step--;
$keys = count($ranArray);
for($i=0;$i<$keys;$i++)
{
$retArray[] = $ranArray[$i];
$i = $i + $step;
}
return $retArray;
}
// usage: myRange(low,high, ... [optional step]);
// example: print_r(myRange(1,11,2));
// output: Array ( [0] => 1
// [1] => 4
// [2] => 7
// [3] => 10 )
Just a quick note, generally 'for' loops are not recommended, but in this case it is
better because of the lack of associative indices.