title: Getting best array value based on a priority list
body: <p>I'll try and explain this the best I can.</p>
  
  <p>I have an array called <code>$linkSets</code>, and it has array entires that look like:</p>
  
  <pre><code>&lt;string&gt;,&lt;integer&gt;
  &lt;string&gt;,&lt;integer&gt;
  &lt;string&gt;,&lt;integer&gt;
  </code></pre>
  
  <p>I also have a priority list, that goes in this order: <code>22 -&gt; 18 -&gt; 35 -&gt; 34</code>. I would like to check each integer in the <code>$linkSets</code> array, and get the best <code>&lt;string&gt;</code> from the same array entry based on the <code>&lt;integer&gt;</code>.</p>
  
  <p>I wrote up code that looks like this:</p>
  
  <pre><code>foreach($linkSets as $link)
  {
      $parts = explode(',', $link);
      if($parts[1] == 22) {
          $best = $parts[0];
          break;
      }
      if($parts[1] == 18) {
          $best = $parts[0];
          break;
      }
      if($parts[1] == 35) {
          $best = $parts[0];
          break;
      }
      if($parts[1] == 34) {
          $best = $parts[0];
          break;
      }
  }
  echo "best: $best";
  </code></pre>
  
  <p>But as you can probably see it doesn't work, it doesn't obey the priority list.</p>
  
  <p>I can't think of any way to do this without looping through the <code>$linkSets</code> array multiple times.</p>