fammi capire....
in $valore = max(array($riga['tempo_cons'])); hai valori sparsi o in un qualche ordine crescente o decrescente?