尝试与对象的动态数组进行比较时遇到问题。
目的:
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;
}
}
我正在做的是为 2 个人分配他们的技能。人 A 和 B 可以拥有任意数量的技能。Skill::Source 通过布尔值识别它来自 A 人。
$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;
}
}
我的问题是,如果说 Person_A 有 5 个技能,而 Person_B 有 2 个技能,则 Array_uintersect_assoc() 不会检查 Person_A 的所有 5 个技能
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] => )
现在,如果我使用 Array_uintersect(),当调用可调用函数时,它不会分别将 Person_A::Skills 分配给 $Skill_A 和将 Person_B::Skills 分配给 $Skill_B,而且似乎将技能分配给参数似乎是随机的在 Callable 函数内部。
$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] => )
正如您在这里看到的那样,有一半的时间调用该函数,甚至没有从两个不同的人进行比较。只有最后两个调用实际上比较了 Person_A 和 Person_B。
任何帮助将不胜感激,谢谢。