If I have a string in php and I need to do something if the last digit equals 9 how can I do it? For example,
$cost = '23829';
TRUE
or
$cost = '2382';
FALSE
or
$cost = '9';
TRUE
or
$cost = '9999998';
FALSE
Basically if the last number is 9 times original number by 2, I tried the following methods but they do not work.
$cost = strrev($cost);
if ($cost[0] == 9) $cost = strrev($cost) * 2;
and
if (substr($cost, -1) === '9') .......
They do not work as expected.
Try either:
or: