首页 >后端开发 >php教程 > 数组算法解决思路

数组算法解决思路

WBOY
WBOY原创
2016-06-13 13:51:31710浏览

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