I have the following code which groups my users by role. It all works well but I feel I could have done this more elegantly. Is there a better way?
<?php $userrole = '';?>
<?php foreach ($users as $user) : ?>
<?php if ($user->userrole != $userrole) :
$userrole = $user->userrole; ?>
<tr>
<td><?=$userrole?></td>
</tr>
<?php endif; ?>
<?php endforeach; ?>