tvance929 Posted March 3, 2009 Share Posted March 3, 2009 Im sorting my associative arrays numerically. I can get a count of the elements. I want to see if the incoming number is higher than the lowest score but I cannot figure out how to call that last score? $scoresArray[$arraycount-1]; thought that might do it .... help? Link to comment https://forums.phpfreaks.com/topic/147770-solved-how-do-i-find-the-last-element-in-my-associative-array/ Share on other sites More sharing options...
premiso Posted March 3, 2009 Share Posted March 3, 2009 Post a print_r of the current array so we can see what we are dealing with. Link to comment https://forums.phpfreaks.com/topic/147770-solved-how-do-i-find-the-last-element-in-my-associative-array/#findComment-775661 Share on other sites More sharing options...
tvance929 Posted March 3, 2009 Author Share Posted March 3, 2009 Array ( [Todd] => 650 [Joe] => 1000 [Fred] => 2000 ) Link to comment https://forums.phpfreaks.com/topic/147770-solved-how-do-i-find-the-last-element-in-my-associative-array/#findComment-775669 Share on other sites More sharing options...
premiso Posted March 3, 2009 Share Posted March 3, 2009 If you arsort the array, then it will put the lowest value at the bottom. Then your code "should" work. EDIT: Never mind, I dunno what I was thinking when I posted that. It is an associative array After that arsort end will grab the last item from the array, which will be the lowest value for you to test. Link to comment https://forums.phpfreaks.com/topic/147770-solved-how-do-i-find-the-last-element-in-my-associative-array/#findComment-775680 Share on other sites More sharing options...
tvance929 Posted March 3, 2009 Author Share Posted March 3, 2009 Thank you very much!! I also see that I need to call reset() to put the pointer back at the top. **I love this language! Link to comment https://forums.phpfreaks.com/topic/147770-solved-how-do-i-find-the-last-element-in-my-associative-array/#findComment-775698 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.