Looking to Build/Redesign a Website or Blog ?

To speak to Rakshit, call +91 968 704 2303

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.

Enter your email address:
Feel free to ask any question. Just leave your comment below and we will answer your comment with in 24 hours.

1 Comment

Leave a Reply

Your email address will not be published.