Reputation: 345
Here is my code
<?php
if( $country==("United Stats" || Canada || United Kingdom) ) {
echo $Country;
}
?>
I want to say "if Country == United Stats 'or' Canada 'or' United Kingdom >>> echo $Country
When i use || it not work correctly What is the wrong please ?
Upvotes: 3
Views: 206
Reputation: 6716
<?php
$country = "Canada";
if( $country=="United Stats" || $country=="Canada" || $country=="United Kingdom" ) {
echo $country;
}
?>
Upvotes: -1
Reputation: 18446
Your code is not valid PHP syntax. This one will work:
<?php
if( $country == "United Stats" || $country == "Canada"
|| $country == "United Kingdom" ) {
echo $country;
}
?>
By the way, you seem to be new to PHP. You should read the documentation and maybe a book to learn the language.
Upvotes: 1
Reputation: 191779
if (in_array($country, array('United Stats', 'Canada', 'United Kingdom'))) {
Upvotes: 3
Reputation: 355
<?php
$cs = array('United States', 'Canada', 'United Kingdom');
if(in_array($country, $cs)){
echo $country
}
?>
Upvotes: 4
Reputation: 2381
you have to compare $country to each variable
if ($country == "United States" ||
$country == "Canada" ||
$country == "United Kingdom") {
echo $country;
}
Upvotes: 2
Reputation: 207943
<?php
if( $country=="United Stats" Or $country=="Canada" Or $country=="United Kingdom" ) {
echo $country;
}
?>
Or
<?php
if( $country=="United Stats" || $country=="Canada" || $country=="United Kingdom" ) {
echo $country;
}
?>
Upvotes: 1
Reputation: 10644
You can't do that, you need to write:
if( $country=="United Stats" || $country=="Canada" || $country=="United Kingdom" ) {
Upvotes: 4