Generation

generate functionSun, 30 Apr 2023

Sacar o filtrar usuarios con varios parámetros

$users = [ ['name' => 'Alejandro', 'age' => 27, 'languages' => ['PHP', 'Python']], ['name' => 'César', 'age' => 30, 'languages' => ['PHP', 'Ruby']], ['name' => 'Yazmin', 'age' => 25, 'languages' => ['PHP', 'Javascript']], ]; function filterUsers($users, $age, $languages) { $result = []; foreach ($users as $user) { if($user['age'] >= $age) { if(count(array_intersect($languages, $user['languages'])) === count($languages)) { $result[] = $user; } } } return $result; } var_dump(filterUsers($users, 26, ['PHP']));

Questions about programming?Chat with your personal AI assistant