这是我的代码
<?php
if( $country==("United Stats" || Canada || United Kingdom) ) {
echo $Country;
}
?>
我想说“如果 Country == United Stats 'or' Canada 'or' United Kingdom >>> echo $Country
当我使用 || 它不能正常工作 请问有什么问题吗?
这是我的代码
<?php
if( $country==("United Stats" || Canada || United Kingdom) ) {
echo $Country;
}
?>
我想说“如果 Country == United Stats 'or' Canada 'or' United Kingdom >>> echo $Country
当我使用 || 它不能正常工作 请问有什么问题吗?
<?php
$cs = array('United States', 'Canada', 'United Kingdom');
if(in_array($country, $cs)){
echo $country
}
?>
你不能这样做,你需要写:
if( $country=="United Stats" || $country=="Canada" || $country=="United Kingdom" ) {
if (in_array($country, array('United Stats', 'Canada', 'United Kingdom'))) {
您必须将 $country 与每个变量进行比较
if ($country == "United States" ||
$country == "Canada" ||
$country == "United Kingdom") {
echo $country;
}
您的代码不是有效的 PHP 语法。这将起作用:
<?php
if( $country == "United Stats" || $country == "Canada"
|| $country == "United Kingdom" ) {
echo $country;
}
?>
顺便说一句,您似乎是 PHP 新手。您应该阅读文档,也许还应该阅读一本书来学习该语言。
<?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;
}
?>
<?php
$country = "Canada";
if( $country=="United Stats" || $country=="Canada" || $country=="United Kingdom" ) {
echo $country;
}
?>