Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 更改所有阵列的最简单方法';谁的钥匙?_Php_Arrays_Key - Fatal编程技术网

Php 更改所有阵列的最简单方法';谁的钥匙?

Php 更改所有阵列的最简单方法';谁的钥匙?,php,arrays,key,Php,Arrays,Key,我正在寻找将所有数组的键更改为所有元素的一个键的方法 array(4) ( "a" => string(4) "foo1" "b" => string(4) "foo2" "c" => string(4) "foo3" "d" => string(4) "foo4" ) …致: array(4) ( "a" => string(4) "foo1" "a" => string(4) "foo2" "a" => string(4

我正在寻找将所有数组的键更改为所有元素的一个键的方法

array(4) (
  "a" => string(4) "foo1"
  "b" => string(4) "foo2"
  "c" => string(4) "foo3"
  "d" => string(4) "foo4"
)
…致:

array(4) (
  "a" => string(4) "foo1"
  "a" => string(4) "foo2"
  "a" => string(4) "foo3"
  "a" => string(4) "foo4"
)
我更喜欢没有任何循环的代码

array(4) (
  "a" => string(4) "foo1"
  "a" => string(4) "foo2"
  "a" => string(4) "foo3"
  "a" => string(4) "foo4"
)
这在PHP中是不可能的。数组不能有多个同名键

但你可以做任何事

$array2['a']=array\u值($array)

这在PHP中是不可能的。数组不能有多个同名键

但你可以做任何事


$array2['a']=array\u值($array)

正如佩卡在评论中所说:


不能有两个相同的钥匙 相同的数组。你怎么说 把他们分开


正如佩卡在评论中所说:


不能有两个相同的钥匙 相同的数组。你怎么说 把他们分开


同一数组中不能有两个相同的键。你如何区分它们?+1,你只需要数组的相反行为,它的元素由唯一键标识。我完全失败了。我没想过。哈哈。不,更像是。。。我读了小胡子的文档,其中有“name”作为数组的键(对于所有元素)。我睡得不好。我没想到它对所有元素都是独一无二的。所以我在这里=在同一数组中不能有两个相同的键。你如何区分它们?+1,你只需要数组的相反行为,它的元素由唯一键标识。我完全失败了。我没想过。哈哈。不,更像是。。。我读了小胡子的文档,其中有“name”作为数组的键(对于所有元素)。我睡得不好。我没想到它对所有元素都是独一无二的。所以我在这里=D@Tatu很抱歉后来我才想到我可以提供另一种方法来做这件事。高拉夫的答案要好得多,我投了票@塔图对不起。。。后来我才想到我可以提供另一种方法来做这件事。高拉夫的答案要好得多,我投了票!