Simple statement problem, unexpected results.

Hi folks,

This seems like it ought to be simple but it is not producing the result I expect, I’m hoping someone can tell me why.

[php]
$wprice = “2.2”;

if (strlen(substr(strrchr($wprice, “.”), 1) == 1)) {echo “TRUE”;}
echo " Result: " . strlen(substr(strrchr($wprice, “.”), 1));
[/php]

The result is 1, as expected. The IF Statement does not echo “TRUE” yet,

[php]
$wprice = “2.2”;

if (strlen(substr(strrchr($wprice, “.”), 1) != 1)) {echo “FALSE”;}
echo " Result: " . strlen(substr(strrchr($wprice, “.”), 1));
[/php]
DOES echo “FALSE”

Why can’t I catch that value in that statement?

Thanks!

[php]if (strlen(substr(strrchr($wprice, “.”), 1)) == 1) {echo “TRUE”;}
echo " Result: " . strlen(substr(strrchr($wprice, “.”), 1));[/php]

Your example is the equivalent to,
[php]if (strlen()) {
echo “TRUE”;
}[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service