如何首先根据键对数组进行排序?

亚历克斯

我试图首先对数组进行排序,然后按字母顺序显示它

   $testArray[test] = 'London';
    $testArray[fsee] = 'Cardiff';
    $testArray[pol] = 'Edinburgh';
    $testArray[bede] = 'Manchester';
    asort($testArray);
    foreach ($testArray as $key => $value) {
        echo $key . ' -- ' . $value . '<br/>';
    }

我喜欢按字母顺序对 test、fsee、pol 和 bede 进行排序,所以它返回

bede -- Manchester
fsee -- Cardiff
pol -- Edinburgh
test -- London
铺路

使用ksort功能。

ksort($testArray);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章