Home  >  Q&A  >  body text

Check if a number is within a range

<?php
        $int = 12;
        $min = 1;
        $max = 100;


        if(filter_var($int,'FILTER_VALIDATE_INT', array("options"=>array("min_range"=>$min,"max_range"=>$max))) === false){
            echo ("The number is valid");
        }else{
            echo ("The number is not valid");
        }               
    ?>


WW2548 days ago1148

reply all(2)I'll reply

  • 电动小老虎

    电动小老虎2017-11-21 00:48:21



    First $arr = range(1,100);

    foreach($arr as $k $v)

    if ($ int === $ v)

    {

    ## Echo ' #} Else {


    Echo 'Not';

    ##}


    # Does it work?

    reply
    0
  • W

    W2017-11-20 16:20:00

    Just remove the quotes from 'FILTER_VALIDATE_INT'

    reply
    0
  • Cancelreply