title: php - finding keys in an array that match a pattern
body: <p>I have an array that looks like: </p>
  
  <pre><code> Array ( [2.5] =&gt; ABDE [4.8] =&gt; Some other value ) 
  </code></pre>
  
  <p>How would I find any key/value pair where the key matches a pattern?  I will know the value of the first digit in the key,but not the second. so for example, using a prefix of "2.", I want to somehow be able to find the key "2.5" and return both the key and the value "ABDE". </p>
  
  <p>I was thinking about using a regular expression with a pattern like: </p>
  
  <pre><code>$prefix = 2;
  $pattern = '/'.$prefix.'\.\d/i';
  </code></pre>
  
  <p>and then looping through the array and checking each key.  (by the way, just for demo purposes, $prefix has been hardcoded to 2, but in the real system, this is a value provided by the user's input).</p>
  
  <p>I'm wondering if there's a simpler way to do this? </p>
  
  <p>Thanks. </p>