Fog Juice Posted June 26, 2009 Share Posted June 26, 2009 Is there a function or shortcut to find the position an array item is in when using the max() function? For example, if I have an array that goes $array = array(1,2,5,123,45,23) and I use max($array), it will return 123 which is in position 3 in the array, but is there a function to get that position? Thanks. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted June 26, 2009 Share Posted June 26, 2009 use strpos(); Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 26, 2009 Share Posted June 26, 2009 use strpos(); Um, say what? The OP asked about finding the index for an item in an array. strpos() is, obviously, for strings. Try this $index = array_search($array, max($array)); Quote Link to comment Share on other sites More sharing options...
Fog Juice Posted June 26, 2009 Author Share Posted June 26, 2009 use strpos(); Um, say what? The OP asked about finding the index for an item in an array. strpos() is, obviously, for strings. Try this $index = array_search($array, max($array)); yes thank you, that is perfect. But I read in the php docs you have it backwards, array_search is array_search(needle, haystack). strpos is opposite where it is strpos(haystack, needle).. funny how they're opposite lol. But thanks a bunch, that's exactly what I needed. 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.