- var_dump: documentation ( source)
<?php
// Documented in the interface.
function formatDuration($locale, $duration) {
$rule = "
%with-words:
0: 0 secondes;
1: 1 seconde;
2: =#0= secondes;
60/60: <%%min<;
61/60: <%%min<, >%with-words>;
3600/60: <%%hr<;
3601/60: <%%hr<, >%with-words>;
86400/86400: <%%day<;
86401/86400: <%%day<, >%with-words>;
604800/604800: <%%week<;
604801/604800: <%%week<, >%with-words>;
%%min:
1: 1 minute;
2: =#0= minutes;
%%hr:
1: 1 heure;
2: =#0= heures;
%%day:
1: 1 jour;
2: =#0= jours;
%%week:
1: 1 semaine;
2: =#0= semaines;
";
$fmt = new NumberFormatter($locale, NumberFormatter::PATTERN_RULEBASED, $rule);
return $fmt->format($duration);
}
var_dump( formatDuration('en_US', 12345) );
var_dump( formatDuration('fr_CA', 12345) );