欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

数组算法解决思路

程序员文章站 2022-04-18 19:53:38
...
数组算法
Array
(
[0] => Array
(
[0] => 1
[1] => 2
)

[1] => Array
(
[0] => 2
[1] => 2
)

[2] => Array
(
[0] => 1
[1] => 2
)

[3] => Array
(
[0] => 2
[1] => 3
)

[4] => Array
(
[0] => 3
[1] => 2
)

[5] => Array
(
[0] => 2
[1] => 2
)

[6] => Array
(
[0] => 2
[1] => 2
)

[7] => Array
(
[0] => 2
[1] => 2
)

[8] => Array
(
[0] => 2
[1] => 2
)

[9] => Array
(
[0] => 3
[1] => 2
)

[10] => Array
(
[0] => 2
[1] => 3
)

[11] => Array
(
[0] => 20
[1] => 30
)

[12] => Array
(
[0] => 35
[1] => 25
)

[13] => Array
(
[0] => 100
[1] => 15
)
[14] => Array
(
[0] => 2
[1] => 1
)

)
目的:里面有重复的只保留一个,然后数据是全部都是唯一的。倒过来的也认为是重复的,譬如1,2和2,1也当作是重复的。。
自己写了个算法。觉得效率太慢了。。大家还有好的算法不?

------解决方案--------------------
array_unique()
------解决方案--------------------
foreach($inputarray as $value) {
foreach($value as $key=>$v) {
$newarray[$v] = $key;
}
}
$array = array_keys($newarray);
print_r($array);
数组算法解决思路

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频