I am trying to compare 2 strings (both alphabets) and run a script depending on if the condition is true or false. Both strings are stored as text on the server and pulled out from different database tables for comparison. The result of the output is displayed at the fron end for the end user.
Take a look at these 2 methods.
a.
if (strcasecmp($str1, $str2) == 0) {
echo 'Both match';
} else {
echo 'Do not match';
}
This failed to run. I keep getting ‘Do not match’ even when both strings are same
b.
Here I removed the else statement and provided an alternative variable.
$output = 'Do not match';
if (strcasecmp($str1, $str2) == 0) {
echo 'Both match';
}
This works when both strings are same or different.
Why is this so?