note 56023 added to function.range

From: Date: Sun, 21 Aug 2005 02:53:48 +0000
Subject: note 56023 added to function.range
Groups: php.notes 
Request: Send a blank email to php-notes+get-93972@lists.php.net to get a copy of this message
since its not stated explicitly above, thought id point out that you arent limited to using integers. however, be careful when doing so, as you might not get the range you expect! to illustrate: <?php $am = range(500,1600,10); $fm = range(88.1,107.9,.2); print_r($am); print_r($fm); ?> print_r($am) yields the expected result: Array ( [0] => 500 [1] => 510 [2] => 520 ... [109] => 1590 [110] => 1600 ) print_r($fm), however, falls a bit (1%) short: Array ( [0] => 88.1 [1] => 88.3 [2] => 88.5 ... [97] => 107.5 [98] => 107.7 ) so, if you want to use a non-integral step size params for numeric ranges, be sure to account for fp representation accuracy and error accumulation; a step size of something like pi or 1/10 could spell disaster for a large range. if in doubt, use integral steps and divide ... something like <?php range(88.1,108,.2) ?> might work to recover 107.9, but would not be scalable like, say <?php array_map(create_function('$x','return $x/10;'),range(881,1079,2)) ?>. -emory ---- Manual Page -- http://www.php.net/manual/en/function.range.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56023 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56023&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56023&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56023&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56023&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56023&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56023&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56023&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#93972) next »