Jump to content

merging arrays - a better way than what I do now?


ultrus

Recommended Posts

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!

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.

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.