I need an efficient PHP array lookup
<p>Let's say that I have some widgets, and each widget has events. Each event has a unique timestamp and a non-unique value.</p>

<p>Since the timestamp is rather large to use as an index (hashing?) I am adding events like this:</p>

<pre><code>$_SESSION['widgets']['datasets'][$i][] = 
                                    array('timestamp' =&gt; $ts, 'value' =&gt; $value);
</code></pre>

<p>However, not every widget has an event at every timestamp, so there are gaps. EDIT: that means that maybe widget A is entered Mon, Tue, Wed and field B is entered Mon, Wed, Fri.  I will then loop through Mon, Tue, Wed, Thur, Fri, Sat, Sun, and want to know which widget had an event that day and what its value was.</p>

<p>After reading all the events from the database, I loop over all known timestamps, then loop over each widget to see if it has an event with that timestamp.</p>

<p>And there I am probably inefficient.</p>

<p>What's the best way to code this?</p>

<pre><code>for each timestamp
   for each widget
      if the widget has an entry with the timestamp, get the value  &lt;=== how?
</code></pre>
