["group.phantom", "group.god", "group.imperator", "group.general", "group.hermit", "group.soldier"]
, а также входные данные: [
[
"permission" => "group.default"
],
[
"permission" => "group.phantom"
],
[
"permission" => "group.general"
]
]
permission
из входных данных? $a = ["group.phantom", "group.god", "group.imperator", "group.general", "group.hermit", "group.soldier"];
$b = [
[
"permission" => "group.default"
],
[
"permission" => "group.phantom"
],
[
"permission" => "group.hermit"
],
[
"permission" => "group.imperator"
],
[
"permission" => "group.god"
],
];
function getItem($a, $b) {
foreach ($a as $item) {
foreach ($b as $data_arr => $data) {
if ($item == $data['permission']) return $item;
}
}
}
print getItem($a, $b);
<?php
$priorities = ["group.phantom", "group.god", "group.imperator", "group.general", "group.hermit", "group.soldier"];
$permissions = [
[
"permission" => "group.default"
],
[
"permission" => "group.phantom"
],
[
"permission" => "group.general"
]
];
$defaultPriority = 'group.default';
$defaultPriorityIndex = count($priorities);
$topPriorityIndex = $defaultPriorityIndex;
foreach ($permissions as $permission) {
$index = array_search($permission['permission'], $priorities);
if ($index !== false && $index < $topPriorityIndex) {
$topPriorityIndex = $index;
}
}
$topPriority = ($topPriorityIndex == $defaultPriorityIndex) ? $defaultPriority : $priorities[$topPriorityIndex];
$permission = array_values(array_intersect($a, array_column($b, 'permission')))[0] ?? null;