title: array_slice for associative array
body: <p>I have an array with indexes as timestamps.
  I tried <code>array_slice</code> to get all values between a time range but it doesn't seem to work.</p>
  
  <pre><code>$data = array_slice(["1549440811" =&gt; 1, "1549448226" =&gt; 2, "1551108588" =&gt; 3 ], 0, 1549460338);
  </code></pre>
  
  <p>I should get the <code>$data</code> as <code>["1549440811" =&gt; 1, "1549448226" =&gt; 2]</code> but it doesn't work that way.</p>
  
  <p>To get the right data I have to use </p>
  
  <pre><code>$data = array_slice(["1549440811" =&gt; 1, "1549448226" =&gt; 2, "1551108588" =&gt; 3 ], 0, 2);
  </code></pre>
  
  <p>But the problem is the records can have random timestamps and no. of records. So I am unable to figure out the offset which is 2 in this case.</p>
  
  <p>I know the code below with a few changes might work for small range but not for my timestamps as <code>$myrange</code> would have a lot of data.</p>
  
  <pre><code>$myrange = range(0,1549460338);
  $output = array_intersect(["1549440811" =&gt; 1, "1549448226" =&gt; 2, "1551108588" =&gt; 3 ] , $myrange );
  </code></pre>
  
  <p>I am avoiding looping through the array as the array has a lot of data. Also I have a lot of timestamps to check. This code is a simplified logic of a bigger code with records from database indexed with timestamps.</p>
  
  <p>Is there any other way I could get the desired data?</p>