ultrus Posted March 21, 2007 Share Posted March 21, 2007 Hello, There are many times when I need to merge the contents of one array into the contents of another. Below is how I make this happen now. Do you know of a better or quicker way to do this? The main reason I am concerned is that the arrays I'm merging now have 40,000+ items in each array. I want to streamline the process if possible. $arrayA = array('item0', 'item1','item2'); $arrayB = array('item3', 'item4', 'item5'); for($i=0;$i<count($arrayB);$i++) { $arrayA[] = $arrayB[$i]; } print_r($arrayA); Thanks much! Link to comment https://forums.phpfreaks.com/topic/43667-merging-arrays-a-better-way-than-what-i-do-now/ Share on other sites More sharing options...
Orio Posted March 21, 2007 Share Posted March 21, 2007 array_merge() EDIT- If you are looking for the fastest way, I think this is it: <?php $arrayA = array('item0', 'item1','item2'); $arrayB = array('item3', 'item4', 'item5'); foreach($arrayB as $val) $arrayA[] = $val; print_r($arrayA); ?> Orio. Link to comment https://forums.phpfreaks.com/topic/43667-merging-arrays-a-better-way-than-what-i-do-now/#findComment-211967 Share on other sites More sharing options...
ultrus Posted March 21, 2007 Author Share Posted March 21, 2007 haha! That's simple. Thanks Link to comment https://forums.phpfreaks.com/topic/43667-merging-arrays-a-better-way-than-what-i-do-now/#findComment-211968 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.