#38453 [Opn->Bgs]: PHP could use a number_between() function

From: Date: Mon, 14 Aug 2006 15:33:20 +0000
Subject: #38453 [Opn->Bgs]: PHP could use a number_between() function
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-100782@lists.php.net to get a copy of this message
ID: 38453 Updated by: tony2001@php.net Reported By: z_rules55 at hotmail dot com -Status: Open +Status: Bogus Bug Type: Feature/Change Request PHP Version: 5.1.4 New Comment: There is absolutely no need for a function that can be implemented in 3 lines of PHP code. Previous Comments: ------------------------------------------------------------------------ [2006-08-14 15:29:57] z_rules55 at hotmail dot com Description: ------------ I think PHP could use a function to determine whether a given number is between a specified lower and upper bound, with the option to specify whether those bounds should be included. It would save people a bit of work in having to code their own function or repeatedly type "if(x < upperBound && x > lowerBound)". A (very, very quick) search through the PEAR Math packages didn't turn up what I'm thinking of. Something like the following code: Reproduce code: --------------- <?php // Returns whether or not an operand is between two // values, and can optionally do the comparison using // upper and lower bounds inclusive. function between($operand, $lower_bound, $upper_bound, $inclusive = true) { if($inclusive) { return ($operand >= $lower_bound && $operand <= $upper_bound); } else { return ($operand > $lower_bound && $operand < $upper_bound); } } ?> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=38453&edit=1

« previous php.bugs (#100782) next »