I have pass trough array to get all ROLE field results from db.
Not I need to search them to find just ROLE_ADMIN roles and count them.
"users": [
[
"ROLE_SUPER_ADMIN"
],
[
"ROLE_STRATEGIST",
"ROLE_ADMIN"
],
[
"ROLE_EDITOR"
],
[
"ROLE_STRATEGIST",
"ROLE_ADMIN"
],
]
And this is my code:
$users = $this->entityManager->getRepository(User::class)->findAll();
$countUsers = [];
foreach ($users as $user) {
$countUsers[] = $user->getRoles();
}
return $countUsers;
Is there a way to go trough array and count all ROLE_ADMIN results?
$role_admin_counter += in_array('ROLE_ADMIN', $user->getRoles()) ? 1 : 0;…?