note 42439 added to function.range

From: Date: Mon, 17 May 2004 00:14:08 +0000
Subject: note 42439 added to function.range
Groups: php.notes 
Request: Send a blank email to php-notes+get-69680@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/function.range.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42439 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42439&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42439&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#69680) next »