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
https://forums.phpfreaks.com/topic/145672-solved-problem-with-array_merge/
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.

 

 

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

 

 

 

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

Archived

This topic is now archived and is closed to further replies.

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