0
Can I have multiple conditions for a single if statement? (PHP)
if ($text == "hello"...){ }
5 Respostas
+ 8
if (cond1&&cond2…){}else if (cond1||cond2…){}else{}
+ 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! :)
+ 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
0
and for multiple codes for one or more conditions?
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.
}