gpt4 book ai didi

php - 重新排列关联数组最优雅的方法是什么?

转载 作者:可可西里 更新时间:2023-11-01 13:44:15 25 4
gpt4 key购买 nike

假设你有一个关联数组

$hash['Fruit'] = 'Apple';
$hash['Name'] = 'Jeff';
$hash['Car'] = 'Ford';

并且您不能更改这些变量的创建顺序。所以 Car 总是在 Name 等之后添加到数组中。将 Car 添加/移动到关联数组的开头而不是结尾(默认)的最漂亮的方法是什么?

最佳答案

$hash = array('Car' => 'Ford') + $hash;

关于php - 重新排列关联数组最优雅的方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2694304/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com