Skip to content

Instantly share code, notes, and snippets.

@Tom32i
Created February 26, 2014 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tom32i/9229408 to your computer and use it in GitHub Desktop.
Save Tom32i/9229408 to your computer and use it in GitHub Desktop.
<?php
function showDiff($year, $month, $day)
{
$sentence = [];
$comma = $this->translator->trans('diff.comma');
$and = $this->translator->trans('diff.and');
if ($year) {
$sentence[] = $this->translator->transChoice('diff.year', $year, array('year' => $year));
}
if ($month) {
$sentence[] = $this->translator->transChoice('diff.month', $month, array('month' => $month));
}
if ($day) {
$sentence[] = $this->translator->transChoice('diff.day', $day, array('day' => $day));
}
$last = array_pop($sentence);
return implode($and, [implode($coma, $sentence), $last]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment