0

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...

3
  • $arr3[33] = $arr1[33]. $arr2[33]; Commented Aug 16, 2012 at 12:05
  • 1
    Do both arrays always contain the same set of keys? Commented Aug 16, 2012 at 12:07
  • Yes...Jack,Thanks,HappyApe it works.. Commented Aug 16, 2012 at 12:39

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.