Is there any php function like in_array for associative arrays that you get with mysql function "mysql_fetch assoc"?
For example, if I have an $ array that looks like this:
array(0=>(array(ID=>1, name=>"Smith"), 1=>(array(ID=>2, name=>"John"))
Is it possible to do something like in_array(key,value,array)?
Or in my case, if I look for the identifier value "1", in_array("ID",1,$array) .
This is my solution, comment it if you think it is right:
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; } }
source share