我有兩個數組與ids作爲鍵和一些領域,我想合併它們,但我不明白爲什麼它不起作用,這裏是我的示例代碼:用相同的鍵合併數組array_merge_recursive不能按預期工作
$Podcasts1 = array("1234" => array('title' => "myTitle", "type" => "myType"));
$Podcast2 = array("1234" => array("content" => "myContent"));
$podcasts = array_merge_recursive($Podcasts1, $Podcast2);
var_dump($Podcasts1, $Podcast2, $podcasts);
有結果:
array:1 [▼
1234 => array:2 [▼
"title" => "myTitle"
"type" => "myType"
]
]
array:1 [▼
1234 => array:1 [▼
"content" => "myContent"
]
]
array:2 [▼
0 => array:2 [▼
"title" => "myTitle"
"type" => "myType"
]
1 => array:1 [▼
"content" => "myContent"
]
]
而且有我woulk喜歡有結果:
array:[
1234 => array(
"title" => "myTitle"
"type" => "myType"
"content" => "myContent")
]
我不明白爲什麼在PHP.net工作給予代碼和我不
代碼:
$ar1 = array("color" => array("favorite" => "red"), 5);
$ar2 = array(10, "color" => array("favorite" => "green", "blue"));
$result = array_merge_recursive($ar1, $ar2);
結果:
Array
(
[color] => Array
(
[favorite] => Array
(
[0] => red
[1] => green
)
[0] => blue
)
[0] => 5
[1] => 10
)
如果鍵是數字它會追加而不是合併成一個陣列 – Jurgo 2015-03-25 13:23:07
我將使用「id_124」爲鍵,由於該值。 – iBadGamer 2015-03-25 13:26:28