I’ve got an array like this
array
2 => string 'Member forum 1'
5 => string 'Member forum 5'
8 => string 'Moderator forum 8'
9 => string 'Member forum 9'
I would like to write a script that, once it hits the Moderator-tag, stops looking for the tag and continue with a variable which contains true or something alike for which I can tell a user is a Moderator on any form of just a normal member.
I have been experimenting with in_array and preg_match but everytime I end up with a false result, cause the last item of the array (Member forum 9) overwrites the true value of the last but one value (Moderator forum 8).
Here is my try. $user_roles being the array mentionned above.
$user_roles = $user->roles;
foreach($user_roles as $value) {
if(preg_match('Moderator', $value)) {
var_dump('yep, moderator');
break;
} elseif(preg_match('Redacteur', $value)) {
var_dump('jep, redacteur');
break;
} else {
var_dump('nope');
}
}
Try something like this?
If there could be more than 1 possible match and you have to process every match: