Implementation code:
1, PHP implementation:
<?php $arr =array (1,1,5,3,2,2); // Because each element needs to be compared with other elements separately //need a double loop for ($i =0; $i <count ($arr); $i + + ) { for ($j =0; $j <count ($arr), $j + +) { //The purpose here is to avoid the array elements and compare themselves if ($i != $j) { //find the equivalent of two elements and set their values to null //If there is an indication that the value is null later, there is no need to assign the value to null again. &nbSp; if ($arr [$i] == $arr [$j] && $arr [$j] != null] { $arr [$i] = $arr [$j]=null; //is here to avoid the meaningless comparisons of J break; } } } echo $arr [$i]. ' <br/> '; }>
2.js implementations:
for (var i in a) {for (Var j in a) {if (i! = j) {if (a[i] = = A[j] && a[j]! = ") { A[i]=a[j]= "; Break }}} Document.writeln (A[i]);}
This article is from the "Everything Possible" blog, please be sure to keep this source http://noican.blog.51cto.com/4081966/1597380
Find two numbers that appear once in the array!