我有一个数组,我需要按名字按字母顺序排序。
如何用 命名每个数组元素,firstname
以便使用排序功能。
功能...
<?php
// fetches all for the users from the table
function fetch_users_directory(){
$result = mysql_query('SELECT `user_lastname` AS `lastname`,
`user_firstname` AS `firstname`,
`user_id` AS `id` FROM `users`');
$users = array();
while(($row = mysql_fetch_assoc($result)) !== false){
$test = mysql_query('SELECT `user_firstname` FROM `users`');
$users[] = $row;
}
return $users;
print_r($user);
?>
结果是……
Array
(
[3] => Array
(
[lastname] => Stoss
[firstname] => Alex
[id] => 1
)
[4] => Array
(
[lastname] => Kennedy
[firstname] => Alice
[id] => 2
)
[5] => Array
(
[lastname] => Williams
[firstname] => Anna
[id] => 3
)
[6] => Array
(
[lastname] => De Jong
[firstname] => Anna
[id] => 4
)
[7] => Array
(
[lastname] => Goodwin
[firstname] => Ash
[id] => 5
)
如何按名字按字母顺序排列,然后按姓氏?