阵列:
$cities = array("Paris" => "10", "Amsterdam" => '20', "California" => '30', "Barcelona" => "70");
排序:
asort($cities);
的print_r :
print_r (array_keys($cities));
结果:
Array ( [0] => Paris [1] => Amsterdam [2] => California [3] => Barcelona )
我想要归还拥有密钥2的城市。(应该是加利福尼亚)
更新
我这样解决了(感谢ArSeN):
$array1 = array_keys($cities);
$city = $array1[2];
答案 0 :(得分:0)
$city = array_keys($array1)[2];
在$ city存储“California”。