title: How can I return the minimum key in an array?
body: <p>Is there an equivalent <code>min()</code> for the keys in an array?</p>
  
  <p>Given the array:</p>
  
  <pre><code>$arr = array(300 =&gt; 'foo', 200 =&gt; 'bar');
  </code></pre>
  
  <p>How can I return the minimum key (<code>200</code>)?</p>
  
  <p>Here's one approach, but I have to imagine there's an easier way.</p>
  
  <pre><code>function minKey($arr) {
      $minKey = key($arr);
      foreach ($arr as $k =&gt; $v) {
          if ($k &lt; $minKey) $minKey = $k;
      }
      return $minKey;
  }
  $arr = array(300 =&gt; 'foo', 200 =&gt; 'bar');
  echo minKey($arr); // 200
  </code></pre>