**Array a**

```
Array
(
    [0] => Array
        (
            [member_id] => 6
            [sorting] => 0
            [total] => 1
        )

    [1] => Array
        (
            [member_id] => 7
            [sorting] => 1
            [total] => 2
        )

)

```

**Array b**

```
Array
(
    [0] => Array
        (
            [member_id] => 2
            [total] => 3
        )

    [1] => Array
        (
            [member_id] => 6
            [total] => 1
        )

    [2] => Array
        (
            [member_id] => 7
            [total] => 2
        )

)

```

**Question:** Above data I try to loop the array and store into new array like the below **(Final data)**. First of all, if the second array is missing the member data, then I need to get from the first array and store it into a new array. Besides that, I need to get the sorting value from the first array if the sorting is missing. In the end, I able to get all the data nicely but the last value store into it will duplicate. Anyone can help on this :(? My logic stuck at here.

***My code return***

```
Array
(
    [0] => Array
        (
            [member_id] => 6
            [total] => 1
            [sorting] => 0
        )

    [1] => Array
        (
            [member_id] => 7
            [total] => 2
            [sorting] => 1
        )

    [2] => Array
        (
            [member_id] => 7
            [total] => 2
            [sorting] => 
        )

)

```

**Final data should be:**

```
Array
(
    [0] => Array
        (
            [member_id] => 6
            [total] => 1
            [sorting] => 0
        )

    [1] => Array
        (
            [member_id] => 7
            [total] => 2
            [sorting] => 1
        )

    [2] => Array
        (
            [member_id] => 2
            [total] => 3
            [sorting] => 2
        )

)

```

code : <https://3v4l.org/WBLCC>