Answer the question
In order to leave comments, you need to log in
How to find a user and how to find out where there are fewer users?
Hello! There is such an array
$arr = [
'test1' => ['users' => ['test']],
'test2' => ['users' => []],
'test3' => ['users' => []],
'test4' => ['users' => []]
];
Answer the question
In order to leave comments, you need to log in
$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];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question