riad
riad

Reputation: 7194

How to find a numeric value within a range in php

How can I find a value let: 745 is within a range of 0 to 1000 using php?

Upvotes: 3

Views: 2609

Answers (3)

Intrepidd
Intrepidd

Reputation: 20878

Use a condition

<?php
$val = 745;
if ($val >= 0 && $val <= 1000)
{
  // Ok
}
else
{
 // Not ok
}

Upvotes: 1

CodesInChaos
CodesInChaos

Reputation: 108800

How about using <= and >= ?

$x=745;
$inrange=(0<=$x)&&($x<=1000)

Upvotes: 1

Matti Virkkunen
Matti Virkkunen

Reputation: 65126

(0 <= $value && $value <= 1000)

Upvotes: 7

Related Questions