note 52644 modified in function.range by derek

From: Date: Sun, 08 May 2005 22:43:58 +0000
Subject: note 52644 modified in function.range by derek
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-89131@lists.php.net to get a copy of this message
This should emulate range() a little better. <?php function range_wroar($low, $high, $step = 1) { $arr = array(); $step = (abs($step)>0)?abs($step):1; $sign = ($low<=$high)?1:-1; if(is_numeric($low) && is_numeric($high)) { //numeric sequence for ($i = (float)$low; $i*$sign <= $high*$sign; $i += $step*$sign) $arr[] = $i; } else { //character sequence if (is_numeric($low)) return $this->range($low, 0, $step); if (is_numeric($high)) return $this->range(0, $high, $step); $low = ord($low); $high = ord($high); for ($i = $low; $i*$sign <= $high*$sign; $i += $step*$sign) { $arr[] = chr($i); } } return $arr; } ?> --was-- This should emulate range() a little better. <?php function range_wroar($low, $high, $step = 1) { $arr = array(); $step = (abs($step)>0)?abs($step):1; $sign = ($low<=$high)?1:-1; if(is_numeric($low) && is_numeric($high)) { //numeric sequence for ($i = $low; $i*$sign <= $high*$sign; $i += $step*$sign) $arr[] = $i; } else { //character sequence if (is_numeric($low)) return $this->range($low, 0, $step); if (is_numeric($high)) return $this->range(0, $high, $step); $low = ord($low); $high = ord($high); for ($i = $low; $i*$sign <= $high*$sign; $i += $step*$sign) { $arr[] = chr($i); } } return $arr; } ?> http://php.net/manual/en/function.range.php

« previous php.notes (#89131) next »