niranjnn01 Posted February 18, 2009 Share Posted February 18, 2009 Hello, I am trying to merge two arrays, and the result i get is a an empty array... one of the arrays is empty... but that shouldnt give any problem. $aArray1 = array_merge($aArray1,$aArray2); print_r($aArray1); --->shows blank I tried setting the result to a 3rd array, which now shows blank $aArray3= array(); $aArray3 = array_merge($aArray1,$aArray2); print_r($aArray3); --->shows blank print_r($aArray1); --->correctly shows old values I tried this in my local system, and everything is working correctly... I am thinking now, is some setting of the server interfearing with the working of this function? Anybody encountered a similar problem?.. Please Help.. Quote Link to comment Share on other sites More sharing options...
allworknoplay Posted February 18, 2009 Share Posted February 18, 2009 Can we see your arrays? Quote Link to comment Share on other sites More sharing options...
niranjnn01 Posted February 18, 2009 Author Share Posted February 18, 2009 sure.. one is Array ( [userId] => = "4" [Allow] => = "0" ) and other is empty... and if it gets any content, it will be similar to the above array Quote Link to comment Share on other sites More sharing options...
gizmola Posted February 18, 2009 Share Posted February 18, 2009 php Version difference? If you look at the manual page for this, there's a warning: The behavior of array_merge() was modified in PHP 5. Unlike PHP 4, array_merge() now only accepts parameters of type array. However, you can use typecasting to merge other types. See the example below for details. So you may need to cast both params to array() to insure that it actually works. Quote Link to comment Share on other sites More sharing options...
niranjnn01 Posted February 18, 2009 Author Share Posted February 18, 2009 no.. server has got version 5.2.4 of php Quote Link to comment Share on other sites More sharing options...
allworknoplay Posted February 18, 2009 Share Posted February 18, 2009 sure.. one is Array ( [userId] => = "4" [Allow] => = "0" ) and other is empty... and if it gets any content, it will be similar to the above array Is that even a valid way to create an array? I've never seen it done that way before.. Quote Link to comment Share on other sites More sharing options...
niranjnn01 Posted February 18, 2009 Author Share Posted February 18, 2009 allworknoplay Hello gizmola, your suggestion worked, . The second array, $aArray2, was not an array.. it was being initialized inside some conditions. array_merge is working fine now.. - Dont worry allworknoplay.. i copy pasted the print_r output as an example.. it was not an array declaration Thank you all for your inputs. Rakesh 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.