hadingrh Posted July 13, 2008 Share Posted July 13, 2008 need urgent help from you guys, please.. I have two arrays - Array a = array ( [0] => 214 [1] => 216 [2] => 217 [3] => 452 ) and - Array b = array ( [2] => 228 [3] => 229 ) Question is, how to push the array a to b so the result should be : array ( [0] => 214 [1] => 216 [2] => 228 [3] => 229 [4] => 217 [5] => 452 ) ? Note that, it should be easy if the keys don't have brackets, just sum array a + array b. But they have. Thanks for your kind before Link to comment https://forums.phpfreaks.com/topic/114510-solved-array-problem-merge-array-to-array/ Share on other sites More sharing options...
rmbarnes82 Posted July 13, 2008 Share Posted July 13, 2008 array_merge($array1, $array2); Link to comment https://forums.phpfreaks.com/topic/114510-solved-array-problem-merge-array-to-array/#findComment-588843 Share on other sites More sharing options...
hadingrh Posted July 13, 2008 Author Share Posted July 13, 2008 array_merge($array1, $array2); thanks, but I've tried to merge it before. Your result is, Array ( [0] => 214 [1] => 216 [2] => 217 [3] => 452 [4] => 228 [5] => 229 ) and not as my expected, i.e array ( [0] => 214 [1] => 216 [2] => 228 [3] => 229 [4] => 217 [5] => 452 ) and it should be working if they dont have brackets (just add array a+array b). Why does it have brackets, it's because they produced from query streams. And I dont have a clue to remove them (i.e bracket). Link to comment https://forums.phpfreaks.com/topic/114510-solved-array-problem-merge-array-to-array/#findComment-588848 Share on other sites More sharing options...
hadingrh Posted July 14, 2008 Author Share Posted July 14, 2008 Found how to do it. Simply uses insert_into_array function and modify its input for an array value: foreach ($b as $key=>$val) { $z = insert_into_array(&$a,$key, $val); } Link to comment https://forums.phpfreaks.com/topic/114510-solved-array-problem-merge-array-to-array/#findComment-589461 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.