有没有人知道如何根据项目的翻译对下拉列表进行排序?这是代码:
echo form_open('');
$career = array(
'arquitect' => lang('arquitect'),
'dentists' => lang('dentists'),
'lawyers' => lang('lawyers'),
'teachers' => lang('teachers')
);
echo form_dropdown('career',$career);
echo form_close();
如何根据翻译对下拉列表进行排序,例如西班牙语中的lang('lawyers')将是'Abogado'并且应该处于第一位。
谢谢:)
答案 0 :(得分:0)
lang()
函数应该为每个键提供翻译的值。在这种情况下,您需要做的就是使用asort()
按值对数组进行排序:
echo form_open('');
$career = array(
'arquitect' => lang('arquitect'),
'dentists' => lang('dentists'),
'lawyers' => lang('lawyers'),
'teachers' => lang('teachers')
);
$career = asort($career); // Sort array by translated values
echo form_dropdown('career',$career);
echo form_close();
有关asort()
的更多信息:http://www.php.net/manual/en/function.asort.php