I created separated arrays for admins:
$admins[] = array(
'username' => 'john',
'admin' => '1',
'level' => '1'
);
$admins[] = array(
'username' => 'adam',
'admin' => '1',
'level' => '1'
);
$admins[] = array(
'username' => 'ana',
'admin' => '1',
'level' => '2'
);
Now, I want to get all the usernames show in a select option element. But the usernames should arrange alphabetically. What I did was I combined all of admin arrays into one multidimensional arrays then I created a function to sort the arrays by username.
$items = array();
foreach($admins as $username) {
$items[] = $username;
}
#echo "<pre>";
#print_r($items);
function sortByName($a, $b) {
return $a['username'] - $b['username'];
}
usort($items, 'sortByName');
After that, I tried to show it in the select option element. But the usernames are not arranged.
<select name="support-name">
<option value="" required>select</option>
<?
foreach ($admins as $admin){?>
<option value="<?=$admin['username']?>"><?=ucwords($admin['username'])?></option>
<?}
?>
<?}
?>
</select>