2013-04-28 74 views
2

I have two arrays with same key names and some times value may be same. I want to append these two arrays into one new array. I have added screen shot of these array. I found array_merge but I saw it overrides instead of append. Is there any function in php to do this or I have write custome function. 如何追加合并两个关联数组有相同的密钥

我有两个数组有相同的密钥的名称和一些时间值可能是相同的。我想将这两个数组附加到一个新数组中。我添加了这些数组的屏幕截图。我发现array_merge,但我看到它重写而不是追加。有没有在PHP中的任何功能做到这一点,或者我已经写了custome功能。

+0

所以,你要得到的阵列具有相同的键不止一次? – 2013-04-28 09:26:59

+0

或者,您希望'lat'和'lng'字段放在'latitude'和'longitude'字段中? (统一密钥) – 2013-04-28 09:31:04

+0

@FabienMénager我希望新的数组将在索引0处具有一个旧数组并且在索引1处具有另一个旧数组。我需要一个多维数组 – ehp 2013-04-28 09:31:08

回答

5

尝试使用

array_merge_recursive($array1, $array2); 
相关问题