У меня есть три массива
- themesSelected
- relayvantGroups
- topicAssingned
$topicsSelected = [ "T-100","T-600"];
$relavantGroups = [[ "id" => "G-001","name" => "3 A","active"=> false ], ["id"=> "G-002","name"=> "3 B","active"=> false] ];
$topicAssingned = [
"G-001" => [
"groupID" => "G-001",
"groupName" => "3 A",
"topics" => [
"T-100" => [
"topicID" => "T-100"
],
"T-200" => [
"topicID" => "T-200"
]
]
],
"G-002" => [
"groupID" => "G-002",
"groupName" => "3 B",
"topics" => [
"T-400" => [
"topicID" => "T-400"
],
"T-500" => [
"topicID" => "T-500"
]
]
],
];
$ themesВыбранные значения массива (T-100 или T-600) в массиве $ topicAssingned должно быть указано хотя бы одно значение на основе groupID (G-001).$ topicAssedned по темам, topicID: T-100 равен присутствует , поэтому Disable : D
$ themes Выбранные значения массива (T-100 или T-600) должны содержать хотя бы одно значение в $topicAssingned массив, основанный на groupID (G-002).$ topicAssned по темам, topicID: T-100 & T-600 отсутствует , поэтому Disable : A
Ожидаемый результат:
[
"id": "G-001",
"name": "3 A",
"active": false,
"Disable" : "D"
],
[
"id": "G-002",
"name": "3 B",
"active": false,
"Disable" : "A"
]
MyКод
foreach ($relavantGroups as &$g) {
$found = false;
foreach ($topicAssingned as $key => $assigned) {
if ($key === $g["id"]) {
$found = true;
break;
}
}
$g["disable"] = $found ? "D" : "A";
}
echo "<pre>";
print_r($relavantGroups);
Мой вывод
Array
(
[0] => Array
(
[id] => G-001
[name] => 3 A
[active] =>
[disable] => D
)
[1] => Array
(
[id] => G-002
[name] => 3 B
[active] =>
[disable] => D
)
)