Reputation: 25
I'm using the Yii framework. I want to show specific content if a user did not select their location.
So, I am using the following code to show content if no state is selected:
<?php if ($state == NULL) { ?>
And I am using the following code if no city is selected:
<?php if ($city == NULL) { ?>
And they are working perfectly, but how can I combine those two statements so that I can show content if they have no state, AND, no city selected?
Upvotes: 0
Views: 1454
Reputation: 16905
There are four different cases:
if($state == NULL && $city == NULL) {
// both are true
}
else if($state == NULL) {
}
else if{$city == NULL) {
}
else{
// neither is true, i.e. both are selected
}
The order in which they are listed is important: You must check for the case that both conditions are true first!
For more information, see the PHP documentation on logical operators: AND, OR, XOR, NOT.
Upvotes: 1
Reputation: 2141
<?php if ($city == NULL && $state == NULL) { ?>
I suggest that you read about operators in PHP. Also worth reading is the PHP symbol reference FAQ of SO.
Upvotes: 0
Reputation: 2103
if ($city == NULL && $state == NULL)
The &&
means AND
||
would be OR
Upvotes: 0