I have an array that outputs information from DB from a single table as follow:
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...
)
What I'm looking for is to re-build each block of that array so the output would be something like this:
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
)
)
I don't even know how to start the code to make this happen, also, if you notice, the ST and BT keys came from the key address_type which is show in the first array, ST is for "shipping address" and BT is for Billing address, some users have one shipping and one for billing, but there are user who have 3 or more address for shipping...
Any help would be greatly appreciated.
users_info_idand store them in an array. Then loop over that array and query for the unique address types and store those outputs in that same array?$users as $userusing$user['users_info_id']for the database query condition, you could store each row like$user[$addressTypeFromDB] = $dbRow;