English 中文(简体)
重复使用和删除重复使用
原标题:sort an $array of ints by repetition and remove repetitions

i need to do this in php lets say i have [1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,3,4,5,5,5,5,5,5,5,5,5,5,5,9,9,9,9,9] i would like [1,5,9,2,3,4]

但是,我的情况大不相同,但是由我的squlry造成的。

i) 只有一个社会化 at,现在就是如此。

while($row = mysql_fetch_array($result){
         $t = $row[ id_deseada ];
 }

不是这样,一只gues子必须做像第一个例子那样做;按重复发生时所订购的美元计算,并在新阵列中可能放大,有新的实地计算点?

所有这一切都源自于这一质疑:

SlectT articles.id as id_deseada,tags.* 摘自文章,标题WHERE tags.id_article = articles.id and tags. IN(名1,名2,构成搜索投入......)

问题在于,回报是每一方的结果,而且每条都想结果。

最佳回答

第一,产生这样的价值阵列:

$vals = array();
while($row = mysql_fetch_array($result){
         $vals[] = $row[ id_deseada ];
}

然后,countsort:

$valCounts = array_count_values($vals);
arsort($valCounts);
$result = array_keys($valCounts);
问题回答

您实际上可以采用“公平”办法。 例如,我们有这个表:

create table lol (id_deseada int);
insert into lol values (1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(2),(3),(4),(5),(5),(5),(5),(5),(5),(5),(5),(5),(5),(5),(9),(9),(9),(9),(9);

您可选择<代码>id_deseada。 s 从数据库中通过使用分类和定购进行重复分类。

SELECT id_deseada FROM lol
GROUP BY id_deseada
ORDER BY COUNT(*) DESC

结果:1、5、9、3、4。





相关问题
How do I sort enum members alphabetically in Java?

I have an enum class like the following: public enum Letter { OMEGA_LETTER("Omega"), GAMMA_LETTER("Gamma"), BETA_LETTER("Beta"), ALPHA_LETTER("Alpha"), private final String ...

Grokking Timsort

There s a (relatively) new sort on the block called Timsort. It s been used as Python s list.sort, and is now going to be the new Array.sort in Java 7. There s some documentation and a tiny Wikipedia ...

Sorting twodimensional Array in AS3

So, i have a two-dimensional Array of ID s and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array -...

Linq operations against a List of Hashtables?

I m working with a set of legacy DAO code that returns an IList, where each Hashtable represents the row of a dynamically executed SQL query. For example, the List might contain the following records/...

C++ Array Sort Me

Stuck on an array sorter. Have to sort numbers from largest to smallest. I m trying two loops (one nested in the other). Here s the code: int counter=0; // inner counter int counter2=0; // outer ...

Can I Nest OrderBy in .NET?

This doesn t seem to work as I intend. VB.NET: Dim x = Model.Discussions.OrderByDescending(Function(d) d.Messages.OrderByDescending(Function(m) m.Sent).First.Sent) For Each d As Discussion In x ....

sorting elements javascript

I m looking for a way to sort my elements, but it isn t as easy as it sounds. Please let me explain My elements are grouped per 6 elements (thumbnails), each x represents a thumbnail However all ...

热门标签