iarnazca Posted February 20, 2010 Share Posted February 20, 2010 I want to return the array with the highest value. <?php $vote['john'] = 1 $vote['james'] = 1 $vote['john'] = $vote['john'] + 1 ; $max = max($vote) ; echo " " . $vote['$max'] . " " ; ?> How do I get it to output "john" instead? Quote Link to comment Share on other sites More sharing options...
Zyx Posted February 20, 2010 Share Posted February 20, 2010 Have you checked, what max() function returns? It returns the maximum value, not the index of this value in the array, so the conclusion is simple: you have to find another way. Have you thought of writing the maximum value searching algorithm yourself, so that you could program it to find the index, too. I won't give you a ready code - try to write it yourself. It's very easy: just scan the array, store the current maximum value in some extra variable and if you find a greater one, update it. At the same time, remember the index in another variable and that's all. Quote Link to comment Share on other sites More sharing options...
iarnazca Posted February 20, 2010 Author Share Posted February 20, 2010 Thanks for the reply. I know what max() does. I was saying that it doesn't do what I want it to and asking for direction on what to use to get what I want. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.