php - 为什么我不能对这个数组进行排序?
问题描述
我从键值格式的分类术语中获得了这个数组,以填充表单元素选择选项。
除英语以外的其他语言的顺序不正确,因此我尝试对其进行排序但没有结果。
这是数组:
Array
(
[AT] => Autriche
[BE] => Belgique
[BG] => Bulgarie
[HR] => Croatie
[CY] => Chypre
[CZ] => République Tchèque
[DK] => Danemark
)
我尝试 asort() 但它返回“1”。
有人有线索吗?
编辑:
使用的代码:
foreach ($tree as $term) {
$term_object_wrapper = entity_metadata_wrapper('taxonomy_term', $term_object = taxonomy_term_load($term->tid));
if ($term_object_wrapper->field_member_state->value() == 1) {
$iso_code = $term_object_wrapper->iso_3166_1_alpha_2_code->value();
$i18ned_country_term = i18n_taxonomy_localize_terms($term_object);
$output_localized[$iso_code] = $i18ned_country_term->name;
}
}
$foo = asort($output_localized);
print('<pre>');
print_r( $foo );
print('</pre>');
结果为“1”
解决方案
<?php
$array = [
"AT" => "Test1",
"BE" => "Test2",
"BG" => "Test3",
"HR" => "Test4",
"CY" => "Test5",
"CZ" => "Test6",
"DK" => "Test7"
];
asort($array);
echo "<pre>";
print_r($array);
?>
输出:
Array
(
[AT] => Test1
[BE] => Test2
[BG] => Test3
[HR] => Test4
[CY] => Test5
[CZ] => Test6
[DK] => Test7
)
请检查并确认
谢谢
穆图
推荐阅读
- terminal - 如何在 git 上推送我的分支并出现致命错误?
- flutter - 使用 SVG 路径剪切图像
- javascript - 这些http响应结束后我需要返回一个值,无法弄清楚
- amazon-web-services - 如何通过 cfn 模板中的策略控制访问?
- google-apps-script - 参数列表后的 SyntaxError: missing ) (ligne 8, fichier "AGENDA.gs")
- swift - SwiftUI View 也可以水平和垂直滚动,而不是仅垂直滚动
- android - 如何将 AAR 文件转换为 JAR
- javascript - 有没有办法欺骗 vuejs 中的路由器登陆页面的一部分?
- r - 使用 NNETAR 和 BRNN 的集成机器学习模型
- sql - 如何在 SQL 计数中包含某些条件