I'm looking for way to change all array's keys to one key for a开发者_如何学Goll elements.
array(4) (
"a" => string(4) "foo1"
"b" => string(4) "foo2"
"c" => string(4) "foo3"
"d" => string(4) "foo4"
)
...to:
array(4) (
"a" => string(4) "foo1"
"a" => string(4) "foo2"
"a" => string(4) "foo3"
"a" => string(4) "foo4"
)
I would prefer code without any loops.
array(4) (
"a" => string(4) "foo1"
"a" => string(4) "foo2"
"a" => string(4) "foo3"
"a" => string(4) "foo4"
)
This is not possible in PHP. Array can not have more than one key with the same name.
But you can do as
$array2['a'] = array_values($array);
As said by Pekka in comment:
You can't have two identical keys in the same array. How would you tell them apart?
精彩评论