简体   繁体   中英

php if else & URL vars

URL

x.php?foo=100

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) { ).

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.

if ($x = 100) {

sets $x to 100 and evaluates the result. 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

try

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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