我有一个来自 PDO Fetch_assoc 的 var_dumped 数组,例如:
array
0 =>
array
'Client_Firstname' => string 'Sandrah' (length=...)
'Client_Lastname' => string 'Lewis' (length=...)
'Client_Email' => string 'san@lewis.com' (length=...)
'Purchased_ItemId' => int '16' (length=...)
'ItemName' => string 'MiniPad' (length=...)
'ItemPrice' => string '500.00' (length=...)
'ItemType' => string 'Hardware' (length=...)
'date' => string '2013-12-12' (length=...)
1 =>
array
'Client_Firstname' => string 'Derick' (length=...)
'Client_Lastname' => string 'Smith' (length=...)
'Client_Email' => string 'der@smith.com' (length=...)
'Purchased_ItemId' => int '10' (length=...)
'ItemName' => string 'MegaPad' (length=...)
'ItemPrice' => string '1500.00' (length=...)
'ItemType' => string 'Hardware' (length=...)
'date' => string '2013-12-12' (length=...)
2 =>
array
'Client_Firstname' => string 'Sandrah' (length=...)
'Client_Lastname' => string 'Lewis' (length=...)
'Client_Email' => string 'san@lewis.com' (length=...)
'Purchased_ItemId' => int '18' (length=...)
'ItemName' => string 'Xpower Speakers' (length=...)
'ItemPrice' => string '300.00' (length=...)
'ItemType' => string 'Hardware' (length=...)
'date' => string '2013-12-12' (length=...)
3 =>
array
'Client_Firstname' => string 'Sandrah' (length=1)
'Client_Lastname' => string 'Lewis' (length=7)
'Client_Email' => string 'san@lewis.com' (length=7)
'Purchased_ItemId' => int '7' (length=7)
'ItemName' => string 'Lion Belt' (length=7)
'ItemPrice' => string '800.00' (length=7)
'ItemType' => string 'Fashion' (length=7)
'date' => string '2013-12-12' (length=7)
4 =>
array
'Client_Firstname' => string 'Sandrah' (length=1)
'Client_Lastname' => string 'Lewis' (length=7)
'Client_Email' => string 'san@lewis.com' (length=7)
'Purchased_ItemId' => int '27' (length=7)
'ItemName' => string 'FT Card Reader' (length=7)
'ItemPrice' => string '20.00' (length=7)
'ItemType' => string 'Hardware' (length=7)
'date' => string '2013-12-12' (length=7)
5 =>
array
'Client_Firstname' => string 'Jonathan' (length=1)
'Client_Lastname' => string 'Homad' (length=7)
'Client_Email' => string 'jon@homad.com' (length=7)
'Purchased_ItemId' => int '20' (length=7)
'ItemName' => string 'MiniPad' (length=7)
'ItemPrice' => string '500.00' (length=7)
'ItemType' => string 'Hardware' (length=7)
'date' => string '2013-12-12' (length=7)
目的是,在输出中,每个客户的名字、姓氏和电子邮件应该只出现一次,然后是所有他/她的交易。
就像是:
array
0 =>
array
'Client_Firstname' => string 'Sandrah' (length=...)
'Client_Lastname' => string 'Lewis' (length=...)
'Client_Email' => string 'san@lewis.com' (length=...)
'Purchased_ItemId' => int '16' (length=...)
'ItemName' => string 'MiniPad' (length=...)
'ItemPrice' => string '500.00' (length=...)
'ItemType' => string 'Hardware' (length=...)
'date' => string '2013-12-12' (length=...)
'Purchased_ItemId' => int '18' (length=...)
'ItemName' => string 'Xpower Speakers' (length=...)
'ItemPrice' => string '300.00' (length=...)
'ItemType' => string 'Hardware' (length=...)
'date' => string '2013-12-12' (length=...)
'Purchased_ItemId' => int '7' (length=...)
'ItemName' => string 'Lion Belt' (length=...)
'ItemPrice' => string '800.00' (length=...)
'ItemType' => string 'Fashion' (length=...)
'date' => string '2013-12-12' (length=...)
'Purchased_ItemId' => int '27' (length=...)
'ItemName' => string 'FT Card Reader' (length=...)
'ItemPrice' => string '20.00' (length=...)
'ItemType' => string 'Hardware' (length=...)
'date' => string '2013-12-12' (length=...)
1 =>
array
'Client_Firstname' => string 'Derick' (length=...)
'Client_Lastname' => string 'Smith' (length=...)
'Client_Email' => string 'der@smith.com' (length=...)
'Purchased_ItemId' => int '10' (length=...)
'ItemName' => string 'MegaPad' (length=...)
'ItemPrice' => string '1500.00' (length=...)
'ItemType' => string 'Hardware' (length=...)
'date' => string '2013-12-12' (length=...)
2 =>
array
'Client_Firstname' => string 'Jonathan' (length=...)
'Client_Lastname' => string 'Homad' (length=...)
'Client_Email' => string 'jon@homad.com' (length=...)
'Purchased_ItemId' => int '20' (length=...)
'ItemName' => string 'MiniPad' (length=...)
'ItemPrice' => string '500.00' (length=...)
'ItemType' => string 'Hardware' (length=...)
'date' => string '2013-12-12' (length=...)
根据我的说法,每个数组中唯一的唯一标识符是电子邮件地址。所以,我尝试使用 for 循环,foreach 循环尝试根据电子邮件地址对它们进行分组,由其他 SO 相关问题指导,但这还没有实现。
非常感谢任何帮助。