cakephp - 如何对“列表”查找器查询进行排序?结果未按定义的顺序显示
问题描述
这些国家没有按升序排列。
$coutryTable = TableRegistry::get('Country');
$getall = $coutryTable
->find('list', [
'keyField' => 'phonecode',
'valueField' => function ($row) {
return $row['name'] . ' (+ ' . $row['phonecode'] . ')';
}
])
->order([
'Country.name' => 'ASC'
]);
解决方案
尝试排序功能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);
推荐阅读
- python - django.db.utils.IntegrityError:NOT NULL 约束失败:迁移后 new__post_user_post.user_id 错误
- sql - 数量变化时的折扣礼物更新
- javascript - 为什么 Swup.js 不处理相对链接?
- apache-nifi - apache Nifi:updateAttribute 处理器
- python - 如何访问第 n 个嵌套列表,我是否知道嵌套列表的深度?
- python - 在 AWS Lambda 上,Openpyxl 不跟踪图像
- javascript - 无法从捆绑的数据库中读取
- angular - 错误:multi (webpack)-dev-server/client?http://0.0.0.0:0&sockPath=/sockjs-node ./node_modules/@angular/material/prebuilt-themes/indigo-pink.css
- image - 从具有复杂图形的图像中提取几何图案
- python - 如何使用 python 在 Salesforce 中创建案例