This question already has an answer here:
In PHP, say that you have an associative array like this:
$pets = array(
"cats" => 1,
"dogs" => 1,
"fish" => 2
);
How would I find the key with the lowest value and first matching? Here, I'd be looking for cats. Both cats and dogs are 1 value. But i need the first matching cause.
I am using
array_keys($pets, min($pets));
But it gives me the second key(dogs) always. I need to get first key(cats) for lowest value.Is it possible?
Thanks in advance.
</div>