r/PHPhelp • u/Apartipredact_ • Dec 12 '25
Solved String integer comparison
So here I was working the natas 23 web challenge when I encountered a bit of a dilemma. Spoiler alert by the way if anyone cares. Anyways, the code compares a string to an integer, and as I've now learned, when this happens and the string starts with a digit, that number will be used in place of the string for comparison, else the string becomes 0 and evaluation continues. HOWEVER, when using online php compilers that doesn't seem to be happening. Below is the code I've used that is producing a different behavior. In it, the if statement evaluates to true for whatever reason. Does anyone understand what's happening? Because I don't :D:D:D:D :I :I :I :I
$val = "iloveyou";
if(strstr($val, "iloveyou")){
if($val > 10){
echo "All goods";
}
else{
echo "No ten :(";
}
}
else{
echo "No love :( ";
}
View all comments
Show parent comment
2
u/Apartipredact_ Dec 13 '25
Lol thank you for correcting yourself.
The outdated php would make sense seeing as the challenge seems to be from more than 13 years ago.
To be clear, the proper behavior with modern php uses ascii when comparing strings and integers right?