我有一个关联数组,我想在数字中使用哪些键。我的意思是:数组有点像这样:
$countries = array
"AD" => array("AND", "Andorra"),
"BG" => array("BGR", "Bulgaria")
);
显然 AD 是 0,BG 是 1,但是当我打印 $countries[1]
时,它甚至没有显示 "Array"
。
当我打印 $countries[1][0]
时,它也没有显示任何内容。我有 key 的编号,但我不应该使用关联 key 。
最佳答案
array_values
的完美用例:
$countries = array_values($countries);
然后您可以通过索引检索值:
$countries[0][0]; // "AND"
$countries[0][1]; // "Andorra"
$countries[1][0]; // "BGR"
$countries[1][1]; // "Bulgaria"
关于php - 关联到 PHP 中的数值数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8782368/