if-code

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
ben_albrechts
Forum Commoner
Posts: 33
Joined: Wed Oct 26, 2005 3:33 am

if-code

Post by ben_albrechts »

Hey all,
i need some help AGAIN.

I need a code that if $var1 = 1 the outcome = A
but if $var1 = any number from 2 to 10 , the outcome = B
and if $var = more then 10, the outcome = C

is this possible? It's mainly the second bit i have problems with , i dont know how to put 'a number from 2 to 10' in my 'if'-session.

Thanks for the help
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

um if number is greater or equal to 2 and number is less than equal to ten.......

right?
or did i miss something?
User avatar
ambivalent
Forum Contributor
Posts: 173
Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON

Re: if-code

Post by ambivalent »

ben_albrechts wrote:
is this possible? It's mainly the second bit i have problems with , i dont know how to put 'a number from 2 to 10' in my 'if'-session.

Code: Select all

if (($var1 >= 2) && ($var1 <=10)) {

//kinda like that?
User avatar
trukfixer
Forum Contributor
Posts: 174
Joined: Fri May 21, 2004 3:14 pm
Location: Miami, Florida, USA

Re: if-code

Post by trukfixer »

ben_albrechts wrote:Hey all,
i need some help AGAIN.

I need a code that if $var1 = 1 the outcome = A
but if $var1 = any number from 2 to 10 , the outcome = B
and if $var = more then 10, the outcome = C

is this possible? It's mainly the second bit i have problems with , i dont know how to put 'a number from 2 to 10' in my 'if'-session.

Thanks for the help
http://us2.php.net/manual/en/language.c ... ctures.php <--- THE MANUAL

Code: Select all

if($var1 == 1)
{
    $outcome = "A";
}
elseif($var1 >1 && $var1 < 11)
{
     $outcome = "B";
}
else
{
    $outcome = "C";
}
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

learn PHP in 24 hours by Sams is pretty good. I recommend spending the 30-50 bucks on it. You'll pick up a lot of good information,very fast.
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post by harrisonad »

I think Truckfixer gave the solution already.
Post Reply