Home > Backend Development > PHP Tutorial > 求对二组数字按要求排序

求对二组数字按要求排序

WBOY
Release: 2016-06-13 13:14:28
Original
1013 people have browsed it

求对2组数字按要求排序。
$a='213,856,89,63,64,123,58,88,127';
$b='34,769,234,856,235,92,65,88';

也可当做一组数字处理:
$a='213,856,89,63,64,123,58,88,127,34,769,234,856,235,92,65,88';


要求2组数得出最后结果 856,88,213,89,63,64,123,58,127,34,769,234,235,92,65

即对2组数把重复的数组按开始出现顺序排在2组数最前面,余下的非重复的按最初排列顺序。


另求去除一组数字中的重复值,其他按原顺序排序 

$a='23,78,23,80,23,43,68,23,78,23,68';

要的结果 23,78,80,43,68

------解决方案--------------------
第二个简单点
$a=array(23,78,23,80,23,43,68,23,78,23,68);
print_r(array_unique($a));

第一个复杂点
$a=array(213,856,89,63,64,123,58,88,127);
$b=array(34,769,234,856,235,92,65,88);
$a1=array_values(array_intersect($a,$b));
$a2=array_values(array_diff($a,$a1));
$a3=array_values(array_diff($b,$a1));
print_r(array_merge($a1,$a2,$a3));

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template