我有以下常见问题,但无法确定哪种数组函数可能适用于以下格式:
((已尝试array_merge
,array_merge_recursive
,array_combine
,array_splice
,但未按预期工作。)
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
)
)
现在,我需要通过通用的r_sid
和c_id
键合并此数组值;唯一特殊的情况是,如果有d_id
键而不是c_id
,则我们将其与数组中具有相似r_sid
的任何值合并/合并。
如果更容易理解,则最终解决方案应如下所示:
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
)
)
与任何人都不匹配的r_sid
值都应该被丢弃。
感谢您的帮助。非常感谢!
这是一段代码,这是我对如何合并数组的最佳解释: