I have the following issue that seems common but can't figure out which array function might work for the following format:
(Already tried array_merge , array_merge_recursive , array_combine, array_splice but didn't work as expected.)
Array
(
[0] => Array
(
[r_id] => 11
[r_sid] => RC
[d_id] => 2
)
[1] => Array
(
[r_id] => 7
[r_sid] => RC
[c_id] => 51
)
[2] => Array
(
[r_id] => 6
[r_sid] => JN
[c_id] => 52
)
[3] => Array
(
[r_id] => 7
[r_sid] => JN
[c_id] => 51
)
[4] => Array
(
[r_id] => 7
[r_sid] => LG
[c_id] => 51
)
[5] => Array
(
[r_id] => 7
[r_sid] => BN
[c_id] => 51
)
[6] => Array
(
[r_id] => 6
[r_sid] => IVS
[c_id] => 52
)
[7] => Array
(
[r_id] => 7
[r_sid] => IVS
[c_id] => 51
)
)
Now, I need to merge this array values by common r_sid & c_id keys; The only special case scenario is if there is a d_id key instead of c_id then we merge/combine that with any value in the array that has similar r_sid.
The final solution needs to look like this, if thats easier to understand:
Array
(
[0] => Array
(
[r_id] => 11,7
[r_sid] => RC
[d_id] => 2
[c_id] => 51
)
[1] => Array
(
[r_id] => 6,7
[r_sid] => JN, IVS
[c_id] => 52,51
)
)
The r_sid values that do not match with anyone needs to be discarded.
Any help is appreciated. Many thanks!
c_id = 51orc_id = 52together?