看到下面的代码,当多个记录中的状态、编号和日期相同时,我想合并记录,并将不同的版本号合并为一个元素,在一个合并的数组元素中,希望下面的示例更好地解释我是什么后。
我很难想出一种干净有效的方法来做到这一点。有谁能帮帮我吗?我无法针对这个问题指出类似的问题。
假设我有一个数组:
array (size=4)
995 =>
array (size=4)
'status' => string 'accept' (length=6)
'number' => string '130106' (length=6)
'date' => string 'July 11th, 2013' (length=15)
'version_number' => 1
996 =>
array (size=4)
'status' => string 'won' (length=3)
'number' => string '130106' (length=6)
'date' => string 'July 11th, 2013' (length=15)
'version_number' => null
993 =>
array (size=4)
'status' => string 'won' (length=3)
'number' => string '130106' (length=6)
'date' => string 'July 11th, 2013' (length=15)
'version_number' => null
992 =>
array (size=4)
'status' => string 'accept' (length=6)
'number' => string '130106' (length=6)
'date' => string 'July 11th, 2013' (length=15)
'version_number' => 3
期望的结果:
array (size=3)
0 =>
array (size=4)
'status' => string 'accept' (length=6)
'number' => string '130106' (length=6)
'date' => string 'July 11th, 2013' (length=15)
'version_number' => array (1, 3)
1 =>
array (size=4)
'status' => string 'won' (length=3)
'number' => string '130106' (length=6)
'date' => string 'July 11th, 2013' (length=15)
'version_number' => null
2 =>
array (size=4)
'status' => string 'won' (length=3)
'number' => string '130106' (length=6)
'date' => string 'July 11th, 2013' (length=15)
'version_number' => null