0

Can I have multiple conditions for a single if statement? (PHP)

if ($text == "hello"...){ }

18th Jan 2017, 8:18 PM
Litzman H.
Litzman H. - avatar
5 Respostas
+ 8
if (cond1&&cond2…){}else if (cond1||cond2…){}else{}
18th Jan 2017, 8:18 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 2
yes, you could use && and || for that. && is for 'and', || is for 'or'. for instance: if($text == "Hello" && $text2 == "hi"){ code which should be executed when both statements are true; } or: if($text == "Hello" || $text == "bye"){ code which should be executed when $text is either equal to "Hello" or equal to "bye"; } Hope thuis helped! :)
18th Jan 2017, 8:25 PM
kj loosman
kj loosman - avatar
+ 2
Otherwise, you maybe mean use a behaviour as provided by the 'switch-case' statement? http://www.w3schools.com/php/php_switch.asp http://php.net/manual/en/control-structures.switch.php
19th Jan 2017, 8:17 AM
visph
visph - avatar
0
and for multiple codes for one or more conditions?
18th Jan 2017, 8:35 PM
Litzman H.
Litzman H. - avatar
0
you could add as many codes to be executed as you want for the conditions, i'll give an example ;) if($text == "Hello" || $text == "bye"){ echo "the value was "; echo $text; echo "lalalal"; etc. }
18th Jan 2017, 8:41 PM
kj loosman
kj loosman - avatar