How to put variable PHP with smaller and greater value (min and max)

1

Hello, everyone!

I would like to know if there is a possibility to make a variable in PHP with a min and max numeral, for example:

$ var = / a numeral greater than or equal to 10 OR a numeral less than or equal to 20 /;

Is there any way to do this directly in the variable without having to use if or similar?

Thank you in advance. Thank you! : D

    
asked by anonymous 05.11.2016 / 16:49

1 answer

1

If you want a random number:

$var = rand( 10, 20 );

Manual:

  

int rand ( int $min , int $max )


If you want to apply to an existing value

$var = max( min( $var, 20 ), 10 );

Manual:

  

mixed min ( mixed $value1 , mixed $value2 [, mixed $... ] )
mixed max ( mixed $value1 , mixed $value2 [, mixed $... ] )

    
05.11.2016 / 16:55