> $chatModels models in list order, each with a string 'id' * @return list> */ public static function choose(array $chatModels, ?string $default, ?string $tested, int $limit = self::LIMIT): array { $first = []; foreach ([$default, $tested] as $wanted) { if ($wanted === null || $wanted === '') { continue; } foreach ($chatModels as $model) { if (($model['id'] ?? null) === $wanted) { $first[$wanted] = $model; break; } } } $rest = array_values(array_filter($chatModels, static fn(array $m): bool => !isset($first[(string) ($m['id'] ?? '')]))); return array_slice(array_merge(array_values($first), $rest), 0, max($limit, count($first))); } }