- implode: documentation ( source)
- explode: documentation ( source)
<?php
function toCents($amount) {
$cents = explode(',', $amount);
if (!isset($cents[1])) $cents[1] = '00';
return (int) implode($cents);
}
$amount = '10,95';
echo toCents($amount);
echo ' - ';
$amount = '150';
echo toCents($amount);