Samuz Posted May 17, 2012 Share Posted May 17, 2012 So I have two arrays (soon to be multiple). What I want to do is merge all those arrays into one, so that I can then proceed to inserting the data all together. Here's an example of what array1 looks like. Array ( [0] => Array ( [name] => samus1 [forum] => phpfreaks.com ) [1] => Array ( [name] => samus2 [forum] => stackoverflow.com ) ) And array2: Array ( [0] => Array ( [posts] => 25 ) [1] => Array ( [posts] => 2500 ) ) I then tried to do: print_r(array_merge($array1, $array2)); Yet it prints nothing? When I print the other arrays individually the values are shown, but after I use array_merge() it doesn't. Anyone got an idea why? Link to comment https://forums.phpfreaks.com/topic/262666-array_merge/ Share on other sites More sharing options...
smoseley Posted May 17, 2012 Share Posted May 17, 2012 try array_merge_recursive Link to comment https://forums.phpfreaks.com/topic/262666-array_merge/#findComment-1346276 Share on other sites More sharing options...
PravinS Posted May 17, 2012 Share Posted May 17, 2012 array_merge() does not support 2 or multiple dimensional array and array generated by your code seems to be 2 dimensional Link to comment https://forums.phpfreaks.com/topic/262666-array_merge/#findComment-1346278 Share on other sites More sharing options...
Samuz Posted May 17, 2012 Author Share Posted May 17, 2012 Ahh I missed that part in the documentation. Anyway solved now. $i = 0; $new = array(); foreach($array1 as $value) : $new[] = array_merge($value, $array2[$i]); $i++; endforeach; Link to comment https://forums.phpfreaks.com/topic/262666-array_merge/#findComment-1346280 Share on other sites More sharing options...
smoseley Posted May 17, 2012 Share Posted May 17, 2012 array_merge_recursive() didn't work? Link to comment https://forums.phpfreaks.com/topic/262666-array_merge/#findComment-1346300 Share on other sites More sharing options...
Samuz Posted May 17, 2012 Author Share Posted May 17, 2012 array_merge_recursive() didn't work? Nope. Link to comment https://forums.phpfreaks.com/topic/262666-array_merge/#findComment-1346302 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.