ountry code. * * @since 5.4.3 * * @param string $alpha3_code ISO 3166-alpha3 country code * @return string ISO 3166-numeric country code */ public static function alpha3_to_numeric( $alpha3_code ) { return self::alpha2_to_numeric( self::alpha3_to_alpha2( $alpha3_code ) ); } /** * Converts an ISO 3166-alpha3 country code to a calling code. * * @since 5.4.3 * * @param string $alpha3_code ISO 3166-alpha3 country code * @return string calling code */ public static function alpha3_to_calling_code( $alpha3_code ) { return self::alpha2_to_calling_code( self::alpha3_to_alpha2( $alpha3_code ) ); } /** * Converts an ISO 3166-numeric country code to an ISO 3166-alpha2 code. * * @since 5.4.3 * * @param string $numeric ISO 3166-numeric country code * @return string ISO 3166-alpha2 country code */ public static function numeric_to_alpha2( $numeric ) { $codes = array_flip( self::$numeric ); return $codes[$numeric] ?? ''; } /** * Converts an ISO 3166-numeric country code to an ISO 3166-alpha3 code. * * @since 5.4.3 * * @param string $numeric ISO 3166-numeric country code * @return string ISO 3166-alpha3 country code */ public static function numeric_to_alpha3( $numeric ) { return self::alpha2_to_alpha3( self::numeric_to_alpha2( $numeric ) ); } /** * Converts an ISO 3166-numeric country code to a calling code. * * @since 5.4.3 * * @param string $numeric ISO 3166-numeric country code * @return string calling code */ public static function numeric_to_calling_code( $numeric ) { return self::alpha2_to_calling_code( self::numeric_to_alpha2( $numeric ) ); } /** * Converts a country calling code to an ISO 3166-alpha2 code. * * @since 5.4.3 * * @param string $calling_code country calling code (includes leading '+') * @return string ISO 3166-alpha2 code */ public static function calling_code_to_alpha2( $calling_code ) { $flipped_calling_codes = self::get_flipped_calling_codes(); return $flipped_calling_codes[$calling_code] ?? ''; } /** * Converts a country calling code to an ISO 3166-alpha3 code. * * @since 5.4.3 * * @param string $calling_code country calling code (includes leading '+') * @return string ISO 3166-alpha3 code */ public static function calling_code_to_alpha3( $calling_code ) { return self::alpha2_to_alpha3( self::calling_code_to_alpha2( $calling_code ) ); } /** * Converts a country calling code to an ISO 3166-numeric code. * * @since 5.4.3 * * @param string $calling_code country calling code (includes leading '+') * @return string ISO 3166-numeric code */ public static function calling_code_to_numeric( $calling_code ) { return self::alpha2_to_numeric( self::calling_code_to_alpha2( $calling_code ) ); } /** * Gets the flipped version of the calling codes array. * * Since array_flip will fail on the calling codes array due to * having some arrays as values, this custom function is necessary. * * @since 5.4.3 * * @return array */ public static function get_flipped_calling_codes() { if ( null === self::$flipped_calling_codes ) { $flipped_calling_codes = []; foreach ( self::$calling_codes as $alpha2 => $calling_code ) { if ( is_array( $calling_code ) ) { foreach ( $calling_code as $sub_code ) { $flipped_calling_codes[ $sub_code ] = $alpha2; } } else { $flipped_calling_codes[ $calling_code ] = $alpha2; } } self::$flipped_calling_codes = $flipped_calling_codes; } return self::$flipped_calling_codes; } }