I have two array like this and want to merge like
Take 1st index Array 1 check
- if it is present in Array 2
Insert in Array 3
add weight of Array 1 and Array 2 - else if not present
take 1st index of Array 2
Take 1st index of Array 2 and check
- if it is present in Array 1
Insert in Array 3
add weight of Array 1 and Array 2 - else if not present
take 2nd index of Array 1
Take 2nd index of Array 1 and check
- if it is present in Array 2
Insert in Array 3
add weight of Array 1 and Array 2 - else if not present
take 1st index of Array 2
Take 1st index of Array 2 and check
Note above logic is for given example
For Example
Array 1
(
[144] => Array
(
[weight] => 2
)
[145] => Array
(
[weight] => 1
)
[177] => Array
(
[weight] => 1
)
)
Array 2
(
[93] => Array
(
[weight] => 4
)
[133] => Array
(
[weight] => 4
)
[144] => Array
(
[weight] => 4
)
[145] => Array
(
[weight] => 4
)
[141] => Array
(
[weight] => 1
)
)
I want result as
Array 3
(
[144] => Array
(
[weight] => 6
)
[145] => Array
(
[weight] => 5
)
[93] => Array
(
[weight] => 4
)
[133] => Array
(
[weight] => 4
)
[177] => Array
(
[weight] => 1
)
[141] => Array
(
[weight] => 1
)
)
Thanks in Advance
You seems to want second array first,
then append first array
maybe this is works
result
array ( 144 => array ( 'weight' => 2, ), 145 => array ( 'weight' => 1, ), 177 => array ( 'weight' => 1, ), )array ( 93 => array ( 'weight' => 4, ), 133 => array ( 'weight' => 4, ), 144 => array ( 'weight' => 4, ), 145 => array ( 'weight' => 4, ), 141 => array ( 'weight' => 1, ), )Array ( [144] => Array ( [weight] => 6 ) [145] => Array ( [weight] => 5 ) [93] => Array ( [weight] => 4 ) [133] => Array ( [weight] => 4 ) [141] => Array ( [weight] => 1 ) [177] => Array ( [weight] => 1 ) )