ego0 Posted June 13, 2006 Share Posted June 13, 2006 I've hit a brick wall with the a script i'm making.Say I have an array with the values ball,doll,cat,cat,dog,cat,ball,cat.Is there a way to sort the array in order of the most common value inside the array.I know that array_count_values can count the number of a certain value in an array. So mayby I could run a loop to go through the array and count how many of each value are the array then put it into something with the value and the number of recurrences of the value then sort them that way?Is there a much quicker way? Any help appreciated Quote Link to comment https://forums.phpfreaks.com/topic/11870-solvedsort-array-by-popularity/ Share on other sites More sharing options...
ober Posted June 13, 2006 Share Posted June 13, 2006 That's probably the best way to go about it. There are no sort functions that will give you what you want. Quote Link to comment https://forums.phpfreaks.com/topic/11870-solvedsort-array-by-popularity/#findComment-45042 Share on other sites More sharing options...
ego0 Posted June 13, 2006 Author Share Posted June 13, 2006 Thanks, I'll try and go ahead with this method. *sends email to developers demanding a function to do this* Quote Link to comment https://forums.phpfreaks.com/topic/11870-solvedsort-array-by-popularity/#findComment-45044 Share on other sites More sharing options...
ober Posted June 13, 2006 Share Posted June 13, 2006 Post something up when you have something and we can help you. Quote Link to comment https://forums.phpfreaks.com/topic/11870-solvedsort-array-by-popularity/#findComment-45045 Share on other sites More sharing options...
ego0 Posted June 14, 2006 Author Share Posted June 14, 2006 Ok, It worked BUT the array now contains values like:15,cat2,dog10,donkeyBut when sorted using 'rsort' it is sorted by the first number rather than both number like '15'. The previous would sort like this:-2,dog15,cat10,donkeyHow can you sort an array numerically by both digits? Quote Link to comment https://forums.phpfreaks.com/topic/11870-solvedsort-array-by-popularity/#findComment-45656 Share on other sites More sharing options...
ego0 Posted June 14, 2006 Author Share Posted June 14, 2006 SOLVED used sort($array, sort_numeric); Quote Link to comment https://forums.phpfreaks.com/topic/11870-solvedsort-array-by-popularity/#findComment-45668 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.