This is the array I get from the mysql-select:
Array (
[0] => Array (
[ADDRESS] => Name
Street
ZIP CITY
COUNTRY
[PRIMARY] => 0
)
[1] => Array (
[ADDRESS] => Name
Street
ZIP CITY
COUNTRY
[PRIMARY] => 1
)
)
The key PRIMARY is set by PHP with
$primary = ($address['address_book_id'] == $_SESSION['customer_default_address_id']) ? 1 : 0;
'PRIMARY' => $primary
The mysql-array I step through with a foreach loop. How is it possible to sort the array that the array element with PRIMARY = 1 will be printed out at first?
More code to ask more precisly.
$addresses = $db->result("
SELECT address_book_id,
entry_company AS company,
entry_firstname AS firstname,
entry_lastname AS lastname,
entry_street_address AS street_address,
entry_suburb AS suburb,
entry_postcode AS postcode,
entry_city AS city,
entry_state AS state,
entry_country_id AS country_id,
entry_zone_id AS zone_id
FROM " . TABLE_ADDRESS_BOOK . "
WHERE customers_id = " . (int)$_SESSION['customer_id'] . "
ORDER BY firstname,
lastname
");
foreach ($addresses['RESULT'] as $address) {
$format_id = inc_getAddressFormatId($address['country_id']);
$primary = ($address['address_book_id'] == $_SESSION['customer_default_address_id']) ? 1 : 0;
$address_data[] = array(
'ADDRESS' => inc_getAddressFormat($format_id, $address, true, ' ', '<br>'),
'PRIMARY' => $primary,
);
}