动态数组和Array_unintersect_assoc()|| Array_unintersect()

Having trouble trying to compare to dynamic arrays of objects.

Object:

class Skill
{
    public $SkillID;
    public $Profficiency;
    public $Required;
    public $Source;

    public function __construct($SkillID,$Prof,$Req,$Src){
        $this->SkillID = $SkillID;
        $this->Profficiency = $Prof;
        $this->Required = $Req;
        $this->Source = $Src;
    }
}

What I am doing is assigning 2 people their sets of skills. Person A & B can have any number of Skills. Skill::Source identifies that its from person A via a Boolean.

$SkillMatches = array_uintersect_assoc($this->Person_A->Skills,$this->Person_B->Skills,array($this, 'SkillIDComparison'));

private function SkillIDComparison($Skill_A,$Skill_B){
    print_r($Skill_A);
    echo '<br>';
    print_r($Skill_B);
    echo '<br>';
    echo '<br>';
    if ($Skill_A === $Skill_B) {
        return 0;
    } elseif ($Skill_A > $Skill_B) {
        return 1;
    } else {
        return -1;
    }
}

My issue is that if say Person_A has 5 Skills, and Person_B has 2 Skills, Array_uintersect_assoc() , does not check all 5 skills of Person_A

Skill Object ( [SkillID] => 6 [Profficiency] => 1 [Required] => 0 [Source] => 1 ) 
Skill Object ( [SkillID] => 3 [Profficiency] => 2 [Required] => 0 [Source] => ) 

Skill Object ( [SkillID] => 7 [Profficiency] => 1 [Required] => 0 [Source] => 1 ) 
Skill Object ( [SkillID] => 5 [Profficiency] => 2 [Required] => 1 [Source] => ) 

Now if I use Array_uintersect(), when the callable function is called it does not assign Person_A::Skills to $Skill_A and Person_B::Skills to $Skill_B respectfully, as well it seems to be random at which Skills are assigned to the parameters inside the Callable function.

$SkillMatches = array_uintersect($this->Person_A->Skills,$this->Person_B->Skills,array($this, 'SkillIDComparison'));

Skill Object ( [SkillID] => 7 [Profficiency] => 1 [Required] => 0 [Source] => 1 ) 
Skill Object ( [SkillID] => 6 [Profficiency] => 1 [Required] => 0 [Source] => 1 ) 

Skill Object ( [SkillID] => 8 [Profficiency] => 1 [Required] => 0 [Source] => 1 ) 
Skill Object ( [SkillID] => 7 [Profficiency] => 1 [Required] => 0 [Source] => 1 ) 

Skill Object ( [SkillID] => 5 [Profficiency] => 2 [Required] => 1 [Source] => ) 
Skill Object ( [SkillID] => 3 [Profficiency] => 2 [Required] => 0 [Source] => ) 

Skill Object ( [SkillID] => 6 [Profficiency] => 1 [Required] => 0 [Source] => 1 ) 
Skill Object ( [SkillID] => 3 [Profficiency] => 2 [Required] => 0 [Source] => ) 

Skill Object ( [SkillID] => 6 [Profficiency] => 1 [Required] => 0 [Source] => 1 ) 
Skill Object ( [SkillID] => 5 [Profficiency] => 2 [Required] => 1 [Source] => ) 

as you can see here half the time the function is called its not even comparing from the two different people. Only the last two calls actually compare Person_A and Person_B.

Any Assistance would be appreciated, Thanks.

You receive two objects in function SkillIDComparison. And if you want compare properties SkillID, so take them by $Skill_A->SkillID.

So, change all next lines

if ($Skill_A === $Skill_B) {
    return 0;
} elseif ($Skill_A > $Skill_B) {
    return 1;
} else {
    return -1;
}

by

return $Skill_A->SkillID - $Skill_B->SkillID;

Use array_uintersectbecause you want compare values but keys.

I don't know whether this construction array($this, 'SkillIDComparison') is correct. But if use 3rd argument as 'SkillIDComparison' all works OK