php – 合并多个数组,然后按数组值计数排序

前端之家收集整理的这篇文章主要介绍了php – 合并多个数组,然后按数组值计数排序前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
请帮助我,我需要合并多个数组,然后按数组值计数排序.以下是问题:
$array1 = array("abc","def","ghi","jkl","mno");
$array2 = array("mno","mno","pqr","stu");
$array3 = array_merge($array1,$array2);
$array4 = ???

print_r($array4);

我想要$array4的返回值如下:

Array
(
[0] => mno
[1] => ghi
[2] => jkl
[3] => abc
[4] => def
[5] => pqr
[6] => stu
)
你可以做:
$array1 = array("abc",$array2);

// get the array of count.
$array4 = array_count_values($array3);

// sort it in reverse order.
arsort($array4);

// extract just the keys.
$array4 = array_keys($array4);

Working example

原文链接:https://www.f2er.com/php/130815.html

猜你在找的PHP相关文章