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 Quote Link to comment Share on other sites More sharing options...
rmbarnes82 Posted July 13, 2008 Share Posted July 13, 2008 array_merge($array1, $array2); Quote Link to comment 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). Quote Link to comment 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); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.