Results 1 to 3 of 3

Thread: Find Key in array based on stored values

  1. #1
    Join Date
    Oct 2005

    Find Key in array based on stored values

    Hey, im searching for a function(if there is one) that will allow me to get the key of a value in an array. Basically i have an array that is like
    PHP Code:
    $tally[c1] = 3;
    $tally[r1] = 5;
    $tally[ps] = 1
    Now i need to find the highest value in the array which i know i can use
    PHP Code:
    max($tally//Returns 5 
    However what i need to find is i need to get r1, not the 5. There is probally an easy way using max to find the key using another array function but i've yet to be able to figure it out, any suggestions?

  2. #2
    Join Date
    Aug 2004
    PHP Code:
    $key array_search(max($tally), $tally); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

  3. #3
    Join Date
    Oct 2005
    Thanks! knew it would be something simple and short.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles