设置 if 属性

  • 本文关键字:属性 if 设置 php
  • 更新时间 :
  • 英文 :


例如>如果内容=树,则将特殊内容返回到树

正在>索引的内容.php?内容=树

<?php
if (<?= $_GET['content'] ?> == tree) {
echo "text here";
}
else {
echo "nothing to see here";
}
?>

已修复:

<?php
if (isset($_GET['content']) && $_GET['content'] == 'tree') {
echo "text here";
}
else {
echo "nothing to see here";
}
?>

倍数:

<?php
if (isset($_GET['content']) && in_array($_GET['content'], array('tree', 'bird', 'fish', 'taco')) ) {
echo "text here";
}
else {
echo "nothing to see here";
}
?>
首先,

我建议您检查 php 手册上的函数和其他 php 代码,下面是 if/elseif/else 语句的示例:链接

现在,在您的代码中,您做到了:if (<?= $_GET['content'] ?> == tree) {

请注意您如何调用php echo <?= $_GET['content'] ?> == tree作为条件,这是第一个错误,因为您不能将php称为条件,更不用说echo了。这是您应该如何编写代码:

<?php
    if ($_GET['content'] == 'tree') { 
        echo "text here";
    }
    else {
        echo "nothing to see here";
    }
?>

请查看我给你的链接。

最新更新