public static function formatAddress(array $address, $sep = ', ')
    {
        $address = array_merge(
            [
                'firstname' => '',
                'lastname' => '',
                'address1' => '',
                'address2' => '',
                'address3' => '',
                'postcode' => '',
                'city' => '',
                'country_code' => '',
            ],
            $address
        );

        $values = array_map('trim', [
                sprintf('%s %s', $address['firstname'], $address['lastname']),
                $address['address1'],
                $address['address2'],
                $address['address3'],
                $address['postcode'],
                $address['city'],
            ]);

        foreach ($values as $key => $val) {
            if (!$val) {
                unset($values[$key]);
            }
        }

        $fullAddress = implode($sep, $values);

        if ($countryCode = trim($address['country_code'])) {
            if ($fullAddress) {
                $fullAddress .= ' ';
            }

            $fullAddress .= sprintf('(%s)', $countryCode);
        }

        return $fullAddress;
    }
public static function formatAddress(array $address, $sep = ', ')
    {
        $address = array_merge(
            [
                'firstname' => '',
                'lastname' => '',
                'address1' => '',
                'address2' => '',
                'address3' => '',
                'postcode' => '',
                'city' => '',
                'country_code' => '',
            ],
            $address
        );

        $values = array_map('trim', [
                sprintf('%s %s', $address['firstname'], $address['lastname']),
                $address['address1'],
                $address['address2'],
                $address['address3'],
                $address['postcode'],
                $address['city'],
            ]);

        foreach ($values as $key => $val) {
            if (!$val) {
                unset($values[$key]);
            }
        }

        $fullAddress = implode($sep, $values);

        if ($countryCode = trim($address['country_code'])) {
            if ($fullAddress) {
                $fullAddress .= ' ';
            }

            $fullAddress .= sprintf('(%s)', $countryCode);
        }

        return $fullAddress;
    }
public static function formatAddress ( array $ address , $ sep = ', ' ) { $ address = array_merge ( [ 'firstname' => '' , 'lastname' => '' , 'address1' => '' , 'address2' => '' , 'address3' => '' , 'postcode' => '' , 'city' => '' , 'country_code' => '' , ] , $ address ) ; $ values = array_map ( 'trim' , [ sprintf ( '%s %s' , $ address [ 'firstname' ] , $ address [ 'lastname' ] ) , $ address [ 'address1' ] , $ address [ 'address2' ] , $ address [ 'address3' ] , $ address [ 'postcode' ] , $ address [ 'city' ] , ] ) ; foreach ( $ values as $ key => $ val ) { if ( ! $ val ) { unset ( $ values [ $ key ] ) ; } } $ fullAddress = implode ( $ sep , $ values ) ; if ( $ countryCode = trim ( $ address [ 'country_code' ] ) ) { if ( $ fullAddress ) { $ fullAddress .= ' ' ; } $ fullAddress .= sprintf ( '(%s)' , $ countryCode ) ; } return $ fullAddress ; }
Formats an address in an array form.

@param array  $address The address array (required keys: firstname, lastname, address1, postcode, city, country_code)
@param string $sep     The address separator

@return string
Formats an address in an array form .