3

这是我的代码

<?php

if( $country==("United Stats" || Canada || United Kingdom) ) {
   echo $Country;
}

?>

我想说“如果 Country == United Stats 'or' Canada 'or' United Kingdom >>> echo $Country

当我使用 || 它不能正常工作 请问有什么问题吗?

4

7 回答 7

4
<?php
$cs = array('United States', 'Canada', 'United Kingdom');
if(in_array($country, $cs)){
echo $country
}
?>
于 2012-07-11T20:54:06.427 回答
4

你不能这样做,你需要写:

if( $country=="United Stats" || $country=="Canada" || $country=="United Kingdom" ) {
于 2012-07-11T20:52:59.873 回答
3
if (in_array($country, array('United Stats', 'Canada', 'United Kingdom'))) {
于 2012-07-11T20:54:15.007 回答
2

您必须将 $country 与每个变量进行比较

if ($country == "United States" ||
    $country == "Canada" ||
    $country == "United Kingdom") {

    echo $country;
}
于 2012-07-11T20:53:11.997 回答
1

您的代码不是有效的 PHP 语法。这将起作用:

<?php

if( $country == "United Stats" || $country == "Canada"
        || $country == "United Kingdom" ) {
    echo $country;
}

?>

顺便说一句,您似乎是 PHP 新手。您应该阅读文档,也许还应该阅读一本书来学习该语言。

于 2012-07-11T20:54:16.130 回答
1
<?php
if( $country=="United Stats" Or $country=="Canada" Or $country=="United Kingdom" ) {
   echo $country;
}
?>

或者

<?php
if( $country=="United Stats" || $country=="Canada" || $country=="United Kingdom" ) {
   echo $country;
}
?>
于 2012-07-11T20:53:02.197 回答
-1
<?php

$country = "Canada";
if( $country=="United Stats" || $country=="Canada" || $country=="United Kingdom" ) {
   echo $country;
}

?>
于 2012-07-11T20:58:17.580 回答