title: How to find first/second element of associative array when keys are unknown?
body: <p>In PHP when you have an associative array, e.g.:</p>
  
  <pre><code>$groups['paragraph'] = 3
  $groups['line'] = 3
  </code></pre>
  
  <p><strong>what is the syntax to access the first or second element of the array when you don't know the value of the keys</strong>?</p>
  
  <p>Is there something like in a C# LINQ statement where you can say:</p>
  
  <pre><code>$mostFrequentGroup = $groups-&gt;first()?
  </code></pre>
  
  <p>or</p>
  
  <pre><code>$mostFrequentGroup = $groups-&gt;getElementWithIndex(0)?
  </code></pre>
  
  <p>Or do I have to use a foreach statement and pick them out as I do at the bottom of this code example:</p>
  
  <pre><code>//should return "paragraph"
  echo getMostFrequentlyOccurringItem(array('line', 'paragraph', 'paragraph'));
  
  //should return "line"
  echo getMostFrequentlyOccurringItem(array('wholeNumber', 'date', 'date', 'line', 'line', 'line'));
  
  //should return null
  echo getMostFrequentlyOccurringItem(array('wholeNumber', 'wholeNumber', 'paragraph', 'paragraph'));
  
  //should return "wholeNumber"
  echo getMostFrequentlyOccurringItem(array('wholeNumber', '', '', ''));
  
  function getMostFrequentlyOccurringItem($items) {
  
      //catch invalid entry
      if($items == null) {
          return null;
      }
      if(count($items) == 0) {
          return null;
      }
  
      //sort
      $groups = array_count_values($items);
      arsort($groups);
  
      //if there was a tie, then return null
      if($groups[0] == $groups[1]) { //******** HOW TO DO THIS? ***********
          return null;
      }
  
      //get most frequent
      $mostFrequentGroup = '';
      foreach($groups as $group =&gt; $numberOfTimesOccurrred) {
          if(trim($group) != '') {
              $mostFrequentGroup = $group;
              break;
          }
      }
      return $mostFrequentGroup;
  }
  </code></pre>