First of all, I have to mention that I dug into manual and php documents and did not find the answer. Here is the code I'm using:
class chomik {
public $state = 'normal';
public $name = 'no name';
public function __construct($name) {
$this->name = $name;
}
public function __toString() {
return $this->name . " - " . $this->state;
}
}
function compare($a, $b) {
echo("$a : $b<br/>");
if($a != $b) {
return 0;
}
else return 1;
}
$chomik = new chomik('a');
$a = array(5, $chomik, $chomik, $chomik);
$b = array($chomik, 'b', 'c', 'd');
array_diff_uassoc($a, $b, 'compare');
What I thought, array_diff_uassoc will compare all the values of these two arrays, and if the values exist, then the keys will be compared. And the output of this code:
1 : 0
3 : 1
2 : 1
3 : 2
1 : 0
3 : 1
2 : 1
3 : 2
3 : 3
3 : 2
2 : 3
1 : 3
0 : 3
So, first of all, why are some pairs (1: 0 or 3: 1) duplicated? Does this mean that the function has forgotten that it has already compared these items? I thought that it would compare all pairs with equal value, but I do not see it in the output. Did I miss something?
So the question is: what is the exact behavior of this function in terms of the order of comparison, and why do I see this duplication? (my php version if that helps: php version 5.3.6-13ubuntu3.6)
...