我想知道如何使函数返回一个关联数组。我只获取返回数组的值而不是键
答案 0 :(得分:5)
你需要自己设置这些键。如果没有,它会自动添加从0开始的索引。看看我的例子
function myfunc(){
$arr = array();
$arr[] = 'value0';
$arr['key1'] = 'value1';
$arr['key2'] = 'value2';
$arr[] = 'value3';
return $arr;
}
将输出
// you see the first and fourth value has the index 0 and 1,
// the other those that are defined
array(4) {
[0]=>
string(6) "value0"
["key1"]=>
string(6) "value1"
["key2"]=>
string(6) "value2"
[1]=>
string(6) "value3"
}