>> This is a basic question but I'm a basic fellow. If I have an array >> >> $timespread = array("12am-01am"=>0); >> $timespread["01am-02am"]=0; >> $timespread["02am-03am"]=0; etc >> >> Using $time which is a number, I want to add 1 to the value of >> $timespread[$time] without changing the key so if $time =1 >> I want to have $timespread["01am-02am"]=1; >> >> Using $timespread[$time]+=1; doesn't work. > > Nope, you must say > > $timespread["01am-02am"] += 1
I think the problem here is your understanding on how array key's work. The following method would be far more appropriate: <?php // Create 00 to 23 in the array // 00 will store hits between midnight and 1am, // 01 for 1am - 2am ... // 23 for 11pm - midnight $timespread = array(); for ($cnt=0; $cnt<24; $cnt++) { $timespread[str_pad($cnt,2,'0',STR_PAD_LEFT)] = 0; } /* here you must work out the hour, and round *DOWN* (truncate off the minutes .. eg: for the current time */ $timespread[date("H")]++; ?> follow or have I lost ya? -- Dan Hardiker [[EMAIL PROTECTED]] ADAM Software & Systems Engineer -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php