Jump to content

[SOLVED] Problem with array_merge


niranjnn01

Recommended Posts

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..

 

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.