开发者

Why is '==' not working in PHP?

开发者 https://www.devze.com 2022-12-27 19:55 出处:网络
Both values are \'2\' but I am not getting a true. Why? echo $getuser. \"<br />\"; echo $userurl. \"<br />\";

Both values are '2' but I am not getting a true. Why?

 echo $getuser. "<br />"; 
 echo $userurl. "<br />"; 
   开发者_JAVA百科if ($getuser == $userurl) {  
       echo "true <br />";
     }

Result

2
2


Instead of echoing them out, use var_dump() to see exactly what is stored in those variables:

var_dump($getuser); echo "<br />";
var_dump($userurl); echo "<br />";


You probably have some stray spaces or other characters which are not easy, or maybe not possible to visually detect.

use

var_dump($getuser);
var_dump($userurl);

Pay attention to the string length. Consider using trim() if needed


may be contain dummy space in that, use like this

 echo $getuser. "<br />"; 
 echo $userurl. "<br />"; 
   if (trim($getuser) == trim($userurl)) {  
       echo "true <br />";
     }


When I try

$getuser = 2;
$userurl = 2;

echo $getuser. "<br />";
echo $userurl. "<br />";
if ($getuser == $userurl) {
    echo "true <br />";
}

Results:

2
2
true 

Works for me. On XAMPP (Windows) and Linux (Apache) alike. So there's problem probably somewhere in configuration or something...

0

精彩评论

暂无评论...
验证码 换一张
取 消