php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #38453 PHP could use a number_between() function
Submitted: 2006-08-14 15:29 UTC Modified: 2006-08-14 15:33 UTC
From: z_rules55 at hotmail dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.1.4 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: z_rules55 at hotmail dot com
New email:
PHP Version: OS:

 

 [2006-08-14 15:29 UTC] 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);
    }
}
?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-14 15:33 UTC] tony2001@php.net
There is absolutely no need for a function that can be implemented in 3 lines of PHP code.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 03:01:33 2025 UTC