数组算法解决思路

WBOY
Release: 2016-06-13 13:51:31
Original
668 people have browsed it

数组算法
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);

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!