我正在尝试使用PHP的ksort对此数组进行排序:
Array(
[district_name] => District name
[email] => email@email.com
[name] => Name of item
[number] => 191
[phone] => +41234568789
[{attr}id] => 2
[questions] => Array(...)
)
但是包含{attr}...
的密钥不会被排序,它会保持在同一个位置,而其他密钥会被排序。排序这个数组的最佳方法是什么?
答案 0 :(得分:3)
我无法证实这一点。此代码按预期排序(“{attr} id”在结果数组中为最后一个):
$arr = array(
"district_name" => "foo",
"email" => "foo",
"name" => "foo",
"number" => "foo",
"phone" => "foo",
'{attr}id' => "foo",
"questions" => "foo",
);
ksort($arr);
var_dump($arr);
请确保你的源阵列没问题。