如何创建一个函数,以不同的方式使用值PHP查找数组的最后一个键[重复]

This question already has an answer here:

How to get the Cat by using the value Nap in array

["Dog" => "Bite", "Cat" => "Nap"] 

and i want to get Cat using value Nap

</div>
$key = array_search('Nap', $array);

What is not clear in your question is if you already know the entry is the last entry, or if you're searching for a value that is somewhere in your array.