note 114180 added to function.range

From: Date: Tue, 21 Jan 2014 20:32:20 +0000
Subject: note 114180 added to function.range
Groups: php.notes 
Request: Send a blank email to php-notes+get-198293@lists.php.net to get a copy of this message
Despite the line above that says that the $step value should be "given as a positive number," the range() function will in fact correctly handle reversed (decrementing) ranges. For example: <?php print_r( range( 24, 20 ) ); ?> Array ( [0] => 24 [1] => 23 [2] => 22 [3] => 21 [4] => 20 ) <?php print_r( range( 20, 11, -3 ) ); ?> Array ( [0] => 20 [1] => 17 [2] => 14 [3] => 11 ) It will actually ignore the sign of the $step argument, and determine whether to increment or decrement based purely on whether $start > $end or $end > $start. For example: <?php print_r( range( 20, 11, 3 ) ); ?> Array ( [0] => 20 [1] => 17 [2] => 14 [3] => 11 ) <?php print_r( range( 11, 20, -3 ) ); ?> Array ( [0] => 11 [1] => 14 [2] => 17 [3] => 20 ) ---- Server IP: 72.52.91.14 Probable Submitter: 72.52.91.14 ---- Manual Page -- http://php.net/manual/en/function.range.php Edit -- https://master.php.net/note/edit/114180 Del: integrated -- https://master.php.net/note/delete/114180/integrated Del: useless -- https://master.php.net/note/delete/114180/useless Del: bad code -- https://master.php.net/note/delete/114180/bad+code Del: spam -- https://master.php.net/note/delete/114180/spam Del: non-english -- https://master.php.net/note/delete/114180/non-english Del: in docs -- https://master.php.net/note/delete/114180/in+docs Del: other reasons-- https://master.php.net/note/delete/114180 Reject -- https://master.php.net/note/reject/114180 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#198293) next »