国家/地区未按升序显示。
$coutryTable = TableRegistry::get('Country');
$getall = $coutryTable
->find('list', [
'keyField' => 'phonecode',
'valueField' => function ($row) {
return $row['name'] . ' (+ ' . $row['phonecode'] . ')';
}
])
->order([
'Country.name' => 'ASC'
]);
答案 0 :(得分:0)
尝试分类功能https://www.w3schools.com/php/func_array_asort.asp
$coutryTable = TableRegistry::get('Country');
//pr($coutryTable);die();
$getall = $coutryTable->find('list', ['keyField' => 'phonecode', 'valueField' => function ($row) {
return $row['name'] . ' (+ ' . $row['phonecode'] . ')';
}])
->toArray();
asort($getAll);
print_r($getAll);
答案 1 :(得分:0)
$ coutryTable = TableRegistry :: get('Country');
$getall = $coutryTable->find('list', ['keyField' => function ($rows) {
return $rows['name'] . ' (+ ' . $rows['phonecode'] . ')';
}, 'valueField' => function ($row) {
return $row['name'] . ' (+ ' . $row['phonecode'] . ')';
}])->order(['Country.id' => 'ASC']);