在PHP中,可以使用以下函数对数组的键值进行排序:
例如,对一个关联数组进行按键名排序:
$fruits = array("apple" => "red", "banana" => "yellow", "cherry" => "red");
ksort($fruits);
foreach ($fruits as $key => $value) {
echo $key . ": " . $value . "\n";
}
以上代码将输出:
apple: red
banana: yellow
cherry: red