如果x =约翰或债券结果你的名字是john还是债券
,如何显示 <?php
if ($x == "john")
{
?>
you name is john or bond
<?php } ?>
答案 0 :(得分:1)
if ($x == "john" || $x == "bond")
{
// do stuff
}
或者,如果您有许多名称,则可以使用其他结构,例如switch()
:
switch ($x)
{
case "john":
case "bond":
// do something
break;
default:
// or else do this
}
如果你有一个动态的名单,或者你觉得它更具可读性,你也可以使用in_array()
:
if (in_array($x, ["john", "bond"]))
{
// do stuff
}
答案 1 :(得分:0)
试试这个:
<?php
$x="bond";
//$x="john";
if ($x == "john" or $x == "bond") {
echo "Your name is ".$x;
}
?>