title: Creating hour statistics using arrays and memcached
body: <p>I am trying to count how many hits I have on my site each hour, but am not sure how to approach this.</p>
  
  <p>Here is what i have now:</p>
  
  <pre><code>if($cacheAvailable == true){ // WE GOT A CACHE
  
      date_default_timezone_set("UTC");
      $thisHour = date("H", time());
  
      $moveStats = $memcache-&gt;get('moveStats');
  
      if(!$moveStats){
          $todayStats = array(array(hour =&gt; $thisHour, hits =&gt; 1, executetime =&gt; $total_time));
          $memcache-&gt;set('moveStats', $todayStats);
      } 
  
  
      foreach ($moveStats as $k =&gt; $v) {
          if($v['hour'] == $thisHour){
              $moveStats[$k]['hits']=$moveStats[$k]['hits']+1;
          }
      }
  
      $memcache-&gt;set('moveStats', $moveStats);
  
      echo '&lt;pre&gt;';
      print_r($moveStats);
      echo '&lt;/pre&gt;';
  
  }
  </code></pre>
  
  <p>This makes an array like this:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [hour] =&gt; 18
              [hits] =&gt; 6
              [executetime] =&gt; 0
          )
  
  )
  </code></pre>
  
  <p>//##### EDIT ######//</p>
  
  <p>I am able to add to the current hour but I don't know how to add a new hour when the clock turns into the new hour?</p>
  
  <p>Hoping for help and thanks in advance.</p>