【问题标题】:See what variable triggered If statement in PHP?看看 PHP 中什么变量触发了 If 语句?
【发布时间】:2014-05-23 15:42:41
【问题描述】:
$one=$_POST['one'];
$two=$_POST['two'];
$three=$_POST['three'];
$four=$_POST['four'];
$five=$_POST['five'];
$six=$_POST['six'];
$seven=$_POST['seven'];
$eight=$_POST['eight'];
$nine=$_POST['nine'];
$ten=$_POST['ten'];
if ( $one   == "gift" or $two   == "gift" or $three == "gift" or $four  == "gift" or $five  == "gift" or $six   == "gift" or $seven == "gift" or $eight == "gift" or $nine  == "gift" or $ten   == "gift" ) {
 echo "<meta http-equiv='refresh' content='0; url=./gift.php?item=" . ??? . "' />";
}

我在里面放什么???填写触发 if 语句的变量名...

【问题讨论】:

  • 使用数组而不是十个变量。
  • 有趣的事实:OP 已经有一个不错的数组 :)
  • ^ 实际上是一个超级数组...
  • 这很落后...为什么不使用 $_POST['GIFT'] = one->ten ?!?!
  • 大声笑,但你知道像数组一样访问它吗?!

标签: php if-statement syntax syntax-error


【解决方案1】:
$key = array_search('gift', $_POST);
if ($key) {
    echo "$key equals 'gift'";
} else {
    echo "nothing equals 'gift'";
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多