between numbers?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

between numbers?

Post by jeeep »

Here is the basic code

Code: Select all

$number = 46;

if ($number >=45) {echo"greater than 45";}
else {
if ($number < 45) {echo"less than 45";}}
This works correctly buy what I would like to do is narrow it down though, to where it could detect if the number were between 45 and 50.

In theory this:

Code: Select all

$number = 46;

if ($number >=45, <= 50) {echo"between 45 and 50";}
else {
if ($number < 45) {echo"less than 45";}}
But this doesnt work. Anyone have any ideas?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Code: Select all

if ($number >=45 && $number <= 50)
{
    echo"between 45 and 50";
}
elseif ($number < 45) 
{
     echo "less than 45";
}
else
{ 
     echo "more than 45";
}
i think
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

awesome, thanks!
Post Reply