<?php /** * @param array<int> $values * @return array<int, mixed> */ function get_random_keys(array $values, int $limit): array { return $limit > 1 ? array_rand($values, $limit) : [array_rand($values)]; }
Another nice example baked into #PHP why having different return types for the same function is a really bad idea. It just results in way more effort to do things right everywhere this function is used.