title: How to use PHP in_array with associative array?
body: <p>Is there any php function such as in_array for associative arrays you get by the mysql function "mysql_fetch assoc" ?</p>
  
  <p>For example, if I have an $array that looks like this:</p>
  
  <pre><code>array(0=&gt;(array(ID=&gt;1, name=&gt;"Smith"), 1=&gt;(array(ID=&gt;2, name=&gt;"John"))
  </code></pre>
  
  <p>Can I do something like <code>in_array(key,value,array)?</code></p>
  
  <p>Or in my case, if I am looking for the ID value of "1", <code>in_array("ID",1,$array)</code>.</p>
  
  <p>This is my solution, comment on it if you think it's the right way:</p>
  
  <pre><code>function in_assoc_array($key,$value,$array)
  {
      if (empty($array))
          return false;
      else
      {
          foreach($array as $a)
          {
              if ($a[$key] == $value)
                  return true;
          }
          return false;
      }
  }
  </code></pre>