简体   繁体   English

php,如果其他&URL vars

[英]php if else & URL vars

URL 网址

x.php?foo=100 x.php?foo = 100

x.php x.php

$x = $_GET['foo'];

if ($x = 100) {
   echo "yeah";    
}else{
   echo "no";
}

My code doesnt work, where is error? 我的代码不起作用,错误在哪里?

if ($x == "100")

要么

if (intval($x) === 100)

You are using a single equal mark ( = ) instead of two in the IF statement ( if ($x = 100) { ). 您在IF语句中使用单个等号( = )而不是两个( if ($x = 100) { )。

A single equal mark will set the value 100 into $x, and then evaluate the IF statement with it - which evaluates to true in PHP. 单个等号会将值100设置为$ x,然后使用它评估IF语句-在PHP中评估为true。

if ($x = 100) {

sets $x to 100 and evaluates the result. 将$ x设置为100并评估结果。 You want: 你要:

if ($x == '100') {

这是因为您使用赋值语句而不是检查行中的相等性:if($ x = 100)而是尝试if($ x == 100)。

you are not comparing value of x, you are saying that x is equal to 100 您没有比较x的值,而是说x等于100

try 尝试

if($x == 100) { echo "yeah"; if($ x == 100){echo“ yeah”; } }

首先使用isset($_REQUEST['foo'])isset($_GET['foo'])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM