$key, 'description' => $desc, 'roles' => [], ]; } $roleLabel = (string) ($rowRole['description'] ?? $rowRole['role'] ?? $row['role'] ?? ''); if ($roleLabel !== '') { $permMap[$permId]['roles'][] = $roleLabel; } } foreach ($permMap as &$item) { $item['roles'] = array_values(array_unique($item['roles'])); } unset($item); return array_values($permMap); } private function extractIntField(array $row, string $field): int { foreach ($row as $value) { if (!is_array($value)) { continue; } if (array_key_exists($field, $value)) { return (int) $value[$field]; } } if (array_key_exists($field, $row)) { return (int) $row[$field]; } return 0; } }