Question: What is the best way to compare elments in the same array in PHP, so that if there are two elemets with the same values in array A, I can pass a function as argument to do somthing ?

Answer: 
You can use [`array_count_values`](http://www.php.net/manual/en/function.array-count-values.php) and [`in_array`](http://php.net/manual/en/function.in-array.php) functions as:

```
if(in_array(2,array_count_values($array)) {
  // do something
}

```
Use [array\_udiff](http://php.net/array_udiff) or similar (with reference arguments in the callback, if you want to be able to modify the values):

```
$array1 = array('foo', 'bar', 'baz');
$array2 = array('foo', 'baz');

$result = array_udiff($array1, $array2, function(&$a, &$b) {
     if ($a == $b) {
         $a = $b = 'same!';
         return 0;
     }
     return $a > $b ? 1 : -1;
});

print_r($array1); // array('same!', 'bar', 'same!')
print_r($array2); // array('same!', 'same!')

```