$arr = [
'test1' => ['users' => ['test']],
'test2' => ['users' => []],
'test3' => ['users' => []],
'test4' => ['users' => []]
];
$search = 'test';
$contains = array_keys(array_filter($arr, function($item) use ($search) { return in_array($search, $item['users']); }));
print_r($contains); // ['test1']
$keys = array_keys($arr);
usort($keys, function($a, $b) use ($arr) {
return count($arr[$a]['users']) - count($arr[$b]['users']);
});
$shortest = $keys[0];