Is there any php function such as in_array for associative arrays you get by the 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"))
Can I do something like in_array(key,value,array)?
Or in my case, if I am looking for the ID value of "1", in_array("ID",1,$array)
.
This is my solution, comment on it if you think it's the right way:
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;
}
}
Try this..... You can use this function for any depth of the associated array. Just contraint to this function is that the key value would not be repeat any where in array.