我有一個從DB從單一的表如下輸出信息的數組:重建規則的陣列,以多維數組
Array
(
[0] => stdClass Object
(
[users_info_id] => 1
[user_id] => 374
[user_email] => [email protected]
[address_type] => BT
[firstname] => Foo
[lastname] => Faa
[vat_number] =>
[country_code] => US
[address] => Jajajaja
[city] => KOKOKOKOKOKO
[state_code] => MD
[zipcode] => 20745
[phone] => 2401111111
)
[1] => stdClass Object
(
[users_info_id] => 1
[user_id] => 374
[user_email] => [email protected]
[address_type] => ST
[firstname] => Foos
[lastname] => Faas
[vat_number] =>
[country_code] => US
[address] => JSUSUSUS
[city] => LASOSLSL
[state_code] => DC
[zipcode] => 1234
[phone] => 1234567895
)
// ... about 500 records...
)
什麼我要找的是重新構建陣列的每個塊,輸出將是這樣的:
Array
(
[0] => stdClass Object
(
[users_info_id] => 1
[user_id] => 374
[user_email] => [email protected]
[phone] => 3213213213
[bt] => array (
[firstname] => Foo
[lastname] => Faa
[vat_number] =>
[country_code] => US
[address] => Jajajaja
[city] => KOKOKOKOKOKO
[state_code] => MD
[zipcode] => 20745
[phone] => 2401111111
)
[st] => array (
[firstname] => Foos
[lastname] => Faas
[vat_number] =>
[country_code] => US
[address] => JSUSUSUS
[city] => LASOSLSL
[state_code] => DC
[zipcode] => 1234
[phone] => 1234567895
)
)
我甚至不知道如何開始的代碼要做到這一點,另外,如果你注意到,ST和BT鍵從哪個是展會的關鍵address_type來到在第一個陣列中,ST是「送貨地址」,BT是賬單地址,一些用戶有一個船ping和一個帳單,但有一個用戶誰有3個或更多的地址發貨...
任何幫助將不勝感激。
您是否考慮過使用多個查詢?抓住每個唯一的'users_info_id'並將它們存儲在一個數組中。然後遍歷該數組並查詢唯一的地址類型並將這些輸出存儲在同一個數組中? –
因此,如果您使用'$ user ['users_info_id']'作爲$ user'作爲$ user'作爲數據庫查詢條件循環使用,則可以像'$ user [$ addressTypeFromDB] = $ dbRow;' –