Jump to content

Archived

This topic is now archived and is closed to further replies.

marcus

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

Recommended Posts

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

[code]
$rounded = round($answer);

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

Share this post


Link to post
Share on other sites
Not sure what you are trying to achieve, but I'll try...

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

Share this post


Link to post
Share on other sites
Here is a simple script that illustrates one method:
[code]<?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;
?>[/code]

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.