Awkward time processing

From: Date: Thu, 02 Aug 2012 12:51:51 +0000
Subject: Awkward time processing
Groups: php.general 
Request: Send a blank email to php-general+get-318614@lists.php.net to get a copy of this message
This is hideous, can anyone think of a more novel approach? What I have is an array of values and timestamps: 17 15:31 16 15:32 27 15:33 14 15:34 11 15:35 now for a day I should have 1440 entries but there could be spotty results, no data from say 11:59 -> 13:00. What I need is to sum the values for each hour interval. Because the results could be spotty I figured I would need to use a lookup table so that I could zero out any empty hours (this is going to be graphed) So I have this: loop through the set above and do $hour = explode(":", $row[0]); $comp[] = $hour[0] . "||" . $row[1]; $c00 = $c01 = $c02 = $c03 = $c04 .... = 0; for ($a = 0; $a < sizeof($comp); ++ $a) { list($h,$c) = explode("||", $comp[$a]); switch ($h) { case 00: $c00 += $c; break; case 01: $c01+= $c; break; case 02: $c02 += $c; break; case 03: $c03 += $c; break; case 04: $c04 += $c; break; ..... } } Works but wow is it ugly.. Thoughts? -- Paul Halliday http://www.pintumbler.org/

« previous php.general (#318614) next »