| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Soon to be RICHdoggie! Join Date: Jan 2005 Location: UK
Posts: 2,408
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | php if - is this possible? is it possible to do something like this in php? PHP Code: PHP Code: Tom |
| |
| | #4 (permalink) |
| Senior Member Join Date: May 2006
Posts: 1,330
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | you can make use of the switch function ![]() like PHP Code: |
| |
| | THREAD STARTER #5 (permalink) |
| Soon to be RICHdoggie! Join Date: Jan 2005 Location: UK
Posts: 2,408
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | i just really couln't be bothered to write it out full, and if there was a shorter way I would rather have used that. Also, I can't make use of the switch thing because it needs to be if $var == any of these values then do this, otherwise dont. switch would just take too long. Thanks anyhow Tom |
| |
| | #6 (permalink) |
| NamePros Regular Join Date: Dec 2005
Posts: 951
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | no, but why not just make a function out of it. Code: function or($var,$var1,$var2,$var3) {
if($var == "$var2" || $var == "$var2" || $var == "$var3") return true;
else return false;
}
if (or($var1,"blah","blah","blah")) {
} else { } |
| |
| | THREAD STARTER #9 (permalink) | ||||||||
| Soon to be RICHdoggie! Join Date: Jan 2005 Location: UK
Posts: 2,408
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
thanks
| ||||||||
| |
| | #10 (permalink) |
| NamePros Regular Join Date: Dec 2005
Posts: 951
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Nice one Scott. Nested if's Code: if($var == "something") {
if($var == "blah") {
if($var == "something else") {
}
}
} else { } ![]() Code: function or($var) {
for($c=1;$c>count($c);++$c) {
if($var[0] != $var[$c]) { return false }
}
return true;
}
if(or(array($v,"sweet","shivy","something else"))) { echo "sweet"; }
else { echo "dude"; } ????: NamePros.com http://www.namepros.com/showthread.php?t=231959 -
Last edited by bliss; 08-27-2006 at 08:36 AM.
|
| |
| | #11 (permalink) |
| I'll do it ![]() Join Date: Dec 2005 Location: India
Posts: 6,927
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | PHP Code:
__________________ |
| |
| | THREAD STARTER #13 (permalink) |
| Soon to be RICHdoggie! Join Date: Jan 2005 Location: UK
Posts: 2,408
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | lol.. thanks for that. I never knew that was called nested ifs! and tree is right, it dosen't solve it. Its not that big a deal, lol, although thanks for all your help. I was really just wondering if php had the capabilities built in to do something like that, rather than having to write it out in full. Just to save time, lol ![]() Anyhow, thanks a lot everyone. Your scripts and solutions have been most interesting, and in fact some have helped me in other ways! ![]() Thanks Tom |
| |
| | #17 (permalink) |
| I'll do it ![]() Join Date: Dec 2005 Location: India
Posts: 6,927
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | I always go with nested IF's even if it is more then 25 IF's Switch is also good. But sometimes I get confused in it. And IF's are coming out in some kind of rhythym. So it does all the work without thinking how and hey, what to write for the switch.
__________________ |
| |
| | #18 (permalink) | ||||
| NamePros Regular Join Date: Feb 2006 Location: Montreal, Quebec, Canada
Posts: 324
![]() | I misread the original question
Last week I used a nested switches for the first time in a long time. As long as you comment everything and tab the code properly it becomes less confusing ;p | ||||
| |
| | THREAD STARTER #19 (permalink) | ||||
| Soon to be RICHdoggie! Join Date: Jan 2005 Location: UK
Posts: 2,408
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
PHP Code: | ||||
| |