Made it use an array for output

This commit is contained in:
pezcurrel 2022-12-15 23:52:32 +01:00
parent f7c32d00ef
commit fdc7ddbd1f

View file

@ -9,28 +9,30 @@ function ght($ts,$fa=null,$sd=2) {
*/
if ($fa==null)
// $fa=array('g, §g, ','o, §o, ','m, §m, ','s§s');
$fa=array('d, §d, ','h:§h:','m:§m:','s§s');
$fa=array('d§d','h§h','m§m','s§s');
foreach ($fa as $k=>$v)
$fa[$k]=explode('§',$v);
$out='';
$out=[];
//giorni
$x=floor($ts/86400);
if ($x>0)
($x==1) ? $out.=$x.$fa[0][0] : $out.=$x.$fa[0][1];
($x==1) ? $out[]=$x.$fa[0][0] : $out[]=$x.$fa[0][1];
$ts=$ts-$x*86400;
//ore
$x=floor($ts/3600);
if ($x>0)
($x==1) ? $out.=$x.$fa[1][0] : $out.=$x.$fa[1][1];
($x==1) ? $out[]=$x.$fa[1][0] : $out[]=$x.$fa[1][1];
$ts=$ts-$x*3600;
//minuti
$x=floor($ts/60);
if ($x>0)
($x==1) ? $out.=$x.$fa[2][0] : $out.=$x.$fa[2][1];
($x==1) ? $out[]=$x.$fa[2][0] : $out[]=$x.$fa[2][1];
$ts=$ts-$x*60;
//secondi
$x=round($ts,$sd);
($x==1) ? $out.=$x.$fa[3][0] : $out.=$x.$fa[3][1];
if ($x>0)
($x==1) ? $out[]=$x.$fa[3][0] : $out[]=$x.$fa[3][1];
$out=implode(', ',$out);
return($out);
}