1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Between

Discussion in 'Facepalm' started by [deleted], Apr 7, 2017.

  1. [deleted]

    [deleted] Guest

    Hello,
    Is there a way to check if a Number is between two numbers?
    Thank you.
     
  2. [deleted]

    [deleted] Guest

    No answer?!
     
  3. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
  4. [deleted]

    [deleted] Guest

    Am I stupid? I just find things what I already knwo like == or > but not a thing to cjeck if its between
     
  5. KairusDarkSeeker

    KairusDarkSeeker Spider Jockey

    Messages:
    25
    GitHub:
    kairusdarkseeker
    Uhh, can you elaborate? Your question makes us confused
     
  6. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    well you can try making your own func
    here's a concept
    between(a,b):
    a = min a b
    b = max a b
    while(true){
    if a === b
    return a//it's middle
    if a > b or b < a
    return false//it's a even number
    a++
    b--
    }
    it's a concept do not copy, as far as things goes, it's very poorly optimised and should NOT be used in deployment but only as an example
     
  7. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Just use:

    PHP:
    if($number >= $min && $number <= $max){}
     
  8. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
     
  9. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    Yes, yes you are stupid if you recognise the operators but cannot use your initiative to do something as simple as a comparison with them.
    PHP:
    if($a >= $min and $a <= $max) {
        
    // do something
    }
    See how easy this is? We use operators as @SOFe suggested!

    I honestly cannot fathom what brought you to ask this sort of question (yes, I do know this is the facepalm section) as a simple google search would've brought you the answer so much faster and would've actually explained why and how it works.
     
  10. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Please be reminded that $a <= $b < $c does not work as you expect it to. You have to use $a <= $b && $b < $c, because PHP only knows to resolve value by value. (Similar issue: there is no ∈ operator in PHP, so $a == ($b || $c) doesn't work as you expect it to either)
    Because I moved it.
    Be nice ;)
     
  11. [deleted]

    [deleted] Guest

    Thank you Guys for all Answers, especially Sofe's ones.
    I will find my way.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.