Jump to content


Photo

How would I do something like (if ($num == 1 to another number)


  • Please log in to reply
2 replies to this topic

#1 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 18 October 2006 - 05:44 PM

Ok, what I'm trying to do is if the user specifies like an answer between 1 - 10, 11 - 20, 21 - 30... etc... that it will echo off something according to the valued answer

$rounded = round($answer);

if($rounded == 50 - 60){
echo "something here";
};


#2 LazyJones

LazyJones
  • Members
  • PipPipPip
  • Advanced Member
  • 78 posts

Posted 18 October 2006 - 05:50 PM

Not sure what you are trying to achieve, but I'll try...

Forget rounding
if($answer > 10 && $answer < 21) {
echo "Answer is between 10 and 20";
} 


#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 18 October 2006 - 08:18 PM

Here is a simple script that illustrates one method:
<?php
$x = $_GET['a'];
switch (true) {
  case ($x<10):
     $a = 'less than 10';
     break;
  case ($x>10 && $x<20):
        $a = 'between 10 and 20';
        break;
  default:
        $a = '20 or larger';
}
echo $x . ' is ' . $a;
?>

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users