Logicationz Tech

More Intelligent Solutionz…!

Merging Arrays with Reindex and without Reindexing

Hello Friends,

All we know about array_merge(param1,param2) array function in PHP. It may be possible that some begineers didn’t come across this function. For those people, array_merge(param1,param2) will merge two arrays and reindex all elements in array.


   $merged_array = array_merge($firstarray,$secondarray);


Above code will merge both array ($firstarray and $secondarray) in $merged_array and reindex all element starting from zero index.

But there are some cases in which you need to keep the same indexes(preserve numeric keys) of this arrays in newly created merged array. For this situation you can’t go for array_merge function. You can simply use ‘+’ operator and it will append both arrays without reindexing elements.


   $merged_array = $firstarray + $secondarray;


This are the two ways in which you can merge two arrays with reindexing and without reindexing.Look at below links for solutions.

To know more about programming,MYSQL database,php info,php editor,programming php,Open-source,php help and php script , subscribe to our feed by entering email address below. You will get updates via email about every tutorial posted on this site . It will not take more than a sec.


January 3, 2010 - Posted by | Helpful Tips and Tricks | ,

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: