if condition inside echo in php
echo '<option value="'.$value.'" '.(($value=='United States')?'selected="selected"':"").'>'.$value.'</option>';
if condition inside echo in php
echo '<option value="'.$value.'" '.(($value=='United States')?'selected="selected"':"").'>'.$value.'</option>';
php conditionals
#Conditionals
<?php
#Conditionals
/*
== equals
=== identical
< less than
> greater than
<= less than or equal to
>= greate than or equal to
!= not equal to
!== not identrical
*/
$num = 5;
#if($num == 5){
# echo '5 passed';
#}elseif($num == 6){
# echo '6 passed';
# }else{
# echo'did not pass';
# }
#nesting If Statements
if($num>4){
if($num < 10){
echo "$num passed<br>";
}
}
/*
Logical operators can be used
instead of what is above
and &&
or ||
xor means one has to be true but not both
*/
if($num >4 && $num <10){
echo "$num passed using Logical operators";
}
/*
Switch tests for value and then find
a match and do something
*/
$favColor = 'pink';
switch($favColor){
case 'red':
echo '<br>Your favorite color is red';
break;
case 'green':
echo '<br>OH NO!! Your favorite color is green';
break;
case 'blue':
echo '<br>Kool!! Your favorite color is blue';
break;
default:
echo '<br>Yikes! Your favorite color is something else';
}
?>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us