0

IN PHP i have the following arrays.

Array 1

And i have this array:

Array 2

What i want to do is append the second array to the first one, i tried doing it like so:

end($array1);
 foreach($array2 as $key => $value ){
 $array1[$key] = $value;

 }

With this result:

New Array

My question is; How do i put the the values and keys of the second array into the first one?

Answer: due to the answer of Manikiran i now got the following array as a result:

Solution

3
  • If you need more information please ask me, i will stay online until the question is answered Commented Dec 14, 2015 at 8:20
  • In the first array the key is campaign_id while in the second one the key is id. Do you want to keep the key from the second array in the result? Commented Dec 14, 2015 at 8:25
  • can you add to your question what your new array1 should look like? Commented Dec 14, 2015 at 8:33

1 Answer 1

3

array_merge() is the function you are looking for. Try the following code:

$new_array=array_merge($array1,$array2);

For more information, check out the manual

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

4 Comments

Could the person who down voted my answer point out the reason for it?
i agree..they should not downvote post without reason.
@Manikiran . I've down voted your answer because what I've understood from the question, before being edited, your solution wasn't fit. But, of course, after edit is very clear what the op wants.. Is fully his fault for this down vote.. I will up vote your answer as soon as I can.. Thank you for understanding
@MateiMihai No worries pal, it always happens.

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.