Bipin K
Bipin K

Reputation: 105

Append one array to another array with same key

I have two arrays

$array1 = array(33=>'abc,bcd,cde,def');
$array2 = array(33=>'fgh,ghi,hij,ijk');

How I can add two arrays to get the below result?

$array3 = array(33=>'abc,bcd,cde,def,fgh,ghi,hij,ijk');

Thanks in advance...

Upvotes: 0

Views: 698

Answers (1)

hoppa
hoppa

Reputation: 3041

I presume you want to do this automatically for multiple keys. Try something like this:

$newArray = array();
foreach ($array1 as $key => $value) {
    $newArray[$key] = $array1[$key] . ',' . $array2[$key];
}

Keep in mind you will need checks to see if the data is in both arrays if they do not exactly match.

Upvotes: 2

Related Questions