실제로 달성하고 싶은 것을 정리하면 조금 더 도움이 될 것입니다.하지만 계속 진행하려면 여기에 일치하지 않고 한 그룹의 구성원에 대한 모든 일치 항목을 가져 오는 한 가지 방법이 있습니다. 자신의 그룹에서 누군가에게 - 나는 당신의 작업 세트에, 여러 ID 년대 아닌 간단한 1234, 5678를 가진 계획 9 10 11 12 가정합니다 : 마지막으로 하나의 사용자를 찾고
// Build an example array:
$numberSet = array(range(1,4),
range(5,8),
range(9,12));
// The function will return an array of matches when passed the array and the ID:
function findCombos($id, $set)
{
// Store the matches found:
$matches = array();
// Loop through each array in the multidimensional array which was passed:
foreach ($set as $group)
{
// Make sure the ID passed isn't a member of the current array, don't want its matches:
if (!in_array($id, $group))
{
// Loop through each array as the ID isn't a member of this group:
foreach ($group as $member)
{
// Add the match the the matches array:
$matches[] = $member;
}
}
}
// Pass the matches back:
return $matches;
}
일치 :
를
// Find all the matches for ID 2 from the multidimensional array:
$matches = findCombos("2", $numberSet);
// Display the nubmer of matches:
echo "Found ".count($matches)." matches for 2.<br/>";
// Loop through each match found:
foreach ($matches as $match)
{
// Display the results:
echo "2 - ".$match."<br/>";
}
결과 :
Found 8 matches for 2.
2 - 5
2 - 6
2 - 7
2 - 8
2 - 9
2 - 10
2 - 11
2 - 12
모든 가능성을 보여주고 싶었다 경우이 같은 것을 할 수있는 :
$count = 0;
foreach ($numberSet as $group)
{
foreach ($group as $member)
{
$matches = findCombos($member, $numberSet);
$count = $count+count($matches);
foreach ($matches as $match)
{
echo $member." - ".$match.", ";
}
}
}
echo "<br/>Found ".$count." possible combinations.";
결과 :
1-5, 1-6, 1-7, 1-8을, 1 - 9, 1 - 10, 1 - 11, 1 - 12, 2 - 5, 2 - 6, 2 - 7, 2 - 8, 2 - 9, 2 - 10, 2 - 11,2 - 12 3 - 5, 3 - 6, 3 - 7, 3 - 8, 3 - 9, 3 - 10, 3 - 11 3 - 12 4 - 5 4 - 6 4 - 7 , 4 - 9, 4 - 10, 4 - 11, 4, 12, 15, 4, 11, 2, 6-3, 6-4, 6-9, 6-10, 6- 11, 6-12, 7-1,7-2,7-3,7- 4, 7-9, 10, 7-11, 7-12, 8-1, 8-2, 8-3, 8-8, 9-8-10, 8-11, 8-12, 9-19- 2, 9 - 3, 9 - 4, 9-5, 9-6, 9-7,9-8,10-1,10-2,10-3,10-4,10-5,10-- 6, 10-7, 10-8, 11-1, 11-2, 11-3, 11-4, 11-5, 11-6, 11-7, 11-8, 12-1, 12-2 , 12 - 3, 12 - 4, 12-5, 12 - 6, 12-7, 12-8,
경우 chenage $ numberSet에 :
$numberSet = array(array("a","b"),
array("c", "d", "e", "f"),
array("joe", "tom", "same")
);
결과 :
A - C, A - D, A - E, A - F, A - 조하는 - tom, a - same, b - c, b - d, b - e, b - f, b - 조, b - tom, b - 동일, c - a, c - b, c - joe, c - 톰, c - 동일, d - a, d - b, d - 조, d - 톰, d - 동일, e - a, e - b, e - 조, e - 톰, e - 동일, f - a, f - b, f - 조, f - 톰, f - 동일, joe - a, joe - b, 조 - c, joe - d, joe - e, joe - f , 톰 - 대답, 톰 - b, 톰 - c, 톰 - d, 톰 - e, 톰 - f, 같은 - a, 같은 - b, 같은 - c, 같은 - d, f,
그러면 가능한 모든 조합의 목록을 표시하고 싶습니까? 아니면 조합을 찾고 있습니까? 또는 함수를 원하고 ID를 전달하면 해당 ID에 대해 가능한 모든 조합이 반환됩니까? – Scoobler
respone 주셔서 감사합니다! HR에 대한 목록을 보내 주시면 감사하겠습니다. :) – isJustMe