"; echo $userurl. "
"; i...">

Why doesn't '==' work in PHP?

Both values ​​are "2" but I am not getting true. What for?

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

      

Result

2
2

      

+2


a source to share


4 answers


Instead of repeating them, use var_dump()

to see exactly what is stored in these variables:



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

      

+4


a source


You probably have some whitespace or other characters that are not easy or may not be visually detectable.

use



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

      

Pay attention to the length of the string. Consider if necessary with trim ()

+4


a source


can contain dummy space, use that like

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

      

+3


a source


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. In XAMPP (Windows) and Linux (Apache). So the problem is probably somewhere in the configuration or something ...

+1


a source







All Articles