这个问题是'This question' 的后续问题。codeigniter 代码将数据库记录集返回为以下数组。
Array
(
[0] => stdClass Object
(
[user_id] => NLK32439
[first_name] => sdn
[last_name] => hf]zL
[email_address] => user1@hotmail.com
[mobile_number] => 9841349349
[description] => g]kfn
[date_joined] => 09-AUG-12
[status] => 1
[username] => user1
[userpassword] => 691f9298642af07c2d6ea8fef56074201e077b34
)
[1] => stdClass Object
(
[user_id] => NLK94358
[first_name] => alag
[last_name] => k|wfg
[email_address] => user2@gmail.com
[mobile_number] => 823472384723
[description] => g]kfn
[date_joined] => 09-AUG-12
[status] => 1
[username] => user2
[userpassword] => 691f9298642af07c2d6ea8fef56074201e077b34
)
[2] => stdClass Object
(
[user_id] => NLK32437
[first_name] => ;lag
[last_name] => %]qL
[email_address] => user3@msn.com
[mobile_number] => 9851112412
[description] => g]kfn
[date_joined] => 08-AUG-12
[status] => 1
[username] => user3
[userpassword] => 691f9298642af07c2d6ea8fef56074201e077b34
)
[3] => stdClass Object
(
[user_id] => NLK32435
[first_name] => clgn
[last_name] => zdf{
[email_address] => user4@msn.com
[mobile_number] => 984134354
[description] => g]kfn
[date_joined] => 08-AUG-12
[status] => 1
[username] => user4
[userpassword] => 0e025eade868b4b481f41ff7449bc1967261e170
)
)
我要做的就是根据特定条件按“first_name”对数组进行排序。到目前为止,我的 php 代码是-
<?php
usort($array, function ($a, $b) {
static $order = array('c', 's','a',';', 'L');
return array_search($a->first_name, $order) - array_search($b->first_name, $order);
});
?>
我的意图是对数组进行排序,以便以'c'开头的first_name排在第一位,'s'排在第二位,'a'排在第三位,';' 排在第四位。
但是上面的代码没有按预期工作。它按顺序返回记录:
's','a',';','c'
它应该按顺序返回
'c', 's','a',';'
我正在使用自定义 Devnagari 字体,因此键盘中的每个 albhabet 代表 devnagari 中的某些字符。所以在devnagari中,c是第一位的,s是第二位的,以此类推。
任何帮助将不胜感激。提前致谢