我有大约 200 条记录的数组,如下所示:
[0] => Array
(
[sid] => 54
[sname] => vISL User book
[sdate] => 2012-03-01 00:00:00
[pid] => 262
[cid] => 95
[at] =>
[amount] => 0
[psdate] => 2012-03-14 00:00:00
[first_name] => Alan
[last_name] => Darshan
[pcid] => 95
[cname] => Invisal
)
[1] => Array
(
[sid] => 54
[sname] => vISL User book
[sdate] => 2012-03-01 00:00:00
[pid] => 263
[cid] => 94
[at] =>
[amount] => 0
[psdate] => 2012-03-14 00:00:00
[first_name] => umed
[last_name] => sarkar
[pcid] => 92
[cname] => Tisal
)
我想将此数组转换为以下格式。原因是 sid、sname 和 sdate 组合可能有多个 pid、cid ... cname 值:
[0] => Array
(
[sid] => 54
[sname] => vISL User book
[sdate] => 2012-03-01 00:00:00
[parr] => Array
(
[0] => Array
(
[pid] => 262
[cid] => 95
[at] =>
[amount] => 0
[psdate] => 2012-03-14 00:00:00
[first_name] => Alan
[last_name] => Darshan
[pcid] => 95
[cname] => Invisal
)
[1] => Array
(
[pid] => 262
[cid] => 95
[at] =>
[amount] => 0
[psdate] => 2012-03-14 00:00:00
[first_name] => Alan
[last_name] => Darshan
[pcid] => 95
[cname] => Invisal
)
)
)
[1] => Array
(
[sid] => 53
[sname] => tebby book
[sdate] => 2012-04-01 00:00:00
[parr] => Array
(
[0] => Array
(
[pid] => 162
[cid] => 15
[at] =>
[amount] => 1
[psdate] => 2012-03-14 00:00:00
[first_name] => edbey
[last_name] => balh
[pcid] => 93
[cname] => Ansasa
)
[1] => Array
(
[pid] => 212
[cid] => 92
[at] =>
[amount] => 0
[psdate] => 2012-03-14 00:00:00
[first_name] => xyz
[last_name] => def
[pcid] => 91
[cname] => vsall
)
)
)
获得所需数组结构的最佳方法是什么?