Codice PHP:
$num = ...
$lastDigit substr($num, -1);