PHP - if last number in string is equal to 9 do something
<p>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, </p>

<pre><code>$cost = '23829';
TRUE
</code></pre>

<p>or</p>

<pre><code>   $cost = '2382';
   FALSE
</code></pre>

<p>or</p>

<pre><code>   $cost = '9';
   TRUE
</code></pre>

<p>or </p>

<pre><code> $cost = '9999998';
   FALSE
</code></pre>

<p>Basically if the last number is 9 times original number by 2, I tried the following methods but they do not work.</p>

<pre><code> $cost = strrev($cost);
   if ($cost[0] == 9) $cost = strrev($cost) * 2;
</code></pre>

<p>and</p>

<pre><code>if (substr($cost, -1) === '9') .......
</code></pre>

<p>They do not work as expected.</p>
