I want to sort the result based on a result count in php loop.My code in templates looks like this
<?php foreach($groups as $group): ?>
<?php if(count($group->getAllgroupmember()) > 0): ?>
<tr>
<td><?php echo $group->id ?></td>
<td><?php echo $group->name ?></td>
<td><?php echo number_format(count($group->getAllgroupmember())) ?></td>
</tr>
<?php endif ?>
<?php var_dump(count($group->getAllgroupmember())) ?>
<?php endforeach ?>
The var_dump result
int(1) int(1) int(4) int(0) int(1) int(0) int(0) int(0) int(0) int(0) int(1) int(0) int(0) int(0) int(0) int(0) int(0) int(0) int(0) int(0) int(0) int(0) int(0) int(0)
How to sort based on result count? The highest value(4) should be in 0 position. I tried usort function
<?php foreach(usort($groups) as $group): ?>
<?php if(count($group->getAllgroupmember()) > 0): ?>
<tr>
<td><?php echo $group->id ?></td>
<td><?php echo $group->name ?></td>
<td><?php echo number_format(count($group->getAllgroupmember())) ?></td>
</tr>
<?php endif ?>
<?php var_dump(count($group->getAllgroupmember())) . "<br>" ?>
<?php endforeach ?>
But no luck..Any ideas how fullfill this?