php 数组
$arr1 = array(1, 3, 5, 9,34,128,129);$arr2 = array(1, 3, 6, 22,33, 128);
$arr3 = array(128,78,56,33,5,1);
想得到的结果是:
$res = array(1,128,3,5,33,9,34,129,6,22,78,56);
规则是:将3数组合并,重复度最高的往前放
//$arr1 $arr2 $arr3一定是desc就是asc排列
//如果只有$arr1和$arr2两个排序呢,或是再添个$arr4呢
//Thanks~
回复讨论(解决方案)
$arr1 = array(1, 3, 5, 9,34,128,129);$arr2 = array(1, 3, 6, 22,33, 128);$arr3 = array(128,78,56,33,5,1);$t = array_count_values(array_merge($arr1, $arr2, $arr3));arsort($t);print_r(array_keys($t));Array
(
[0] => 1
[1] => 128
[2] => 5
[3] => 33
[4] => 3
[5] => 78
[6] => 56
[7] => 22
[8] => 129
[9] => 9
[10] => 34
[11] => 6
)
仅用内饰函数虽然快,但并不完全符合你的要求
所以还需要自己写点代码
$t = array_count_values(array_merge($arr1, $arr2, $arr3));$res = array();for($max=max($t); $max>0; $max--) $res = array_merge($res, array_keys($t, $max));print_r($res);Array
(
[0] => 1
[1] => 128
[2] => 3
[3] => 5
[4] => 33
[5] => 9
[6] => 34
[7] => 129
[8] => 6
[9] => 22
[10] => 78
[11] => 56
)
嗯,明白,还是版主给力啊~我昨晚也生搬硬套一个,
array_diff不给力啊,所以如此冗余
$arr1 = array(1,2,3,4,5,6,7,8,9,10);$arr2 = array(1,8,9,15,100);$arr3 = array(1,8,15,200);$res = array();$resHigh = array();//高度相似$resMiddle = array();//中$resLow = array();//低$res = array_merge($arr1,$arr2,$arr3);$res = my_array_unique($res); //排除重复$resHigh = array_intersect($arr1,$arr2,$arr3); //交集$resLow = array_merge(array_diff($arr1,$arr2,$arr3),array_diff($arr2,$arr1,$arr3),array_diff($arr3,$arr1,$arr2));//组合差集$res = array_diff($res,$resHigh); //排除High$resMiddle = array_diff($res,$resLow); //排除Low$res = array_merge($resHigh,$resMiddle,$resLow);function my_array_unique($array){//排除重复 $out = array(); foreach ($array as $key=>$value) { if (!in_array($value, $out)){ $out[$key] = $value; } } return $out;} echo "<pre class="brush:php;toolbar:false">";print_r($res);exit;/*( [0] => 1 [1] => 8 [2] => 9 [3] => 15 [4] => 2 [5] => 3 [6] => 4 [7] => 5 [8] => 6 [9] => 7 [10] => 10 [11] => 100 [12] => 200)*/

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version
Chinese version, very easy to use

Notepad++7.3.1
Easy-to-use and free code editor

Dreamweaver Mac version
Visual web development tools
