0

how do i merge sub array into main array.

Array
(
    [0] => Array
        (
            [FirmId] => 1
            [PartyName] => abc medicals
            [PartyCode] => P001
            [SalesmanName] => 
        )

    [1] => Array
        (
            [FirmId] => 2
            [PartyName] => xyz medicals
            [PartyCode] => P001
            [SalesmanName] => 
        )

)
Array
(
    [0] => Array
        (
            [SalesmanName] => abc
        )

    [1] => Array
        (
            [SalesmanName] => xyz
        )

)

Output should be :

Array
(
    [0] => Array
        (
            [FirmId] => 1
            [PartyName] => abc medicals
            [PartyCode] => P001
            [SalesmanName] => abc
        )

    [1] => Array
        (
            [FirmId] => 2
            [PartyName] => xyz medicals
            [PartyCode] => P001
            [SalesmanName] => xyz
        )

)

I tried array_merge($arr1,$arr2); but output was not as expected. Merge 2 nested arrays in one with multiple values This solution is too expensive, actually my first array has 30 columns but i mentioned only 4 to simplify my question. Actually second array is a sliced part of main array need to merge it.

4
  • 1
    Assuming occurance [0] in both arrays point to the correct other array, did you try a simple foreach loop? Commented Feb 1, 2018 at 9:58
  • I was about to write an example using a couple for loops, but it is closed and truly IS a close match to the duplicate Commented Feb 1, 2018 at 10:02
  • I did using for loop but it is too expensive solution to loop again whole array Commented Feb 1, 2018 at 10:16
  • there must be any simple way to do that. Commented Feb 1, 2018 at 10:18

1 Answer 1

-1

http://php.net/manual/en/function.array-merge-recursive.php

you want to use array_merge_recursive()

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

2 Comments

Without a simple demonstration this is really just a comment
array_merge_recursive() is also not working

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.