|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-08-14 15:33 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 10:00:01 2025 UTC |
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); } } ?>