示例#1
0
function list_countries_and_codes()
{
    $countries = get_countries_array();
    foreach ($countries as $key => $value) {
        echo $key . " : " . $value . "\r\n <br>";
    }
}
示例#2
0
function form_country_dropdown($name = "country", $top_countries = array(), $selection = NULL, $show_all = TRUE, $extra_code = NULL)
{
    $countries = get_countries_array();
    $html = "<select name='{$name}' id='{$name}' {$extra_code}>";
    $selected = NULL;
    if (in_array($selection, $top_countries)) {
        $top_selection = $selection;
        $all_selection = NULL;
    } else {
        $top_selection = NULL;
        $all_selection = $selection;
    }
    if (!empty($top_countries)) {
        foreach ($top_countries as $value) {
            if (array_key_exists($value, $countries)) {
                if ($value === $top_selection) {
                    $selected = "SELECTED";
                }
                $html .= "<option value='{$value}' {$selected}>{$countries[$value]}</option>";
                $selected = NULL;
            }
        }
        $html .= "<option>----------</option>";
    }
    if ($show_all) {
        foreach ($countries as $key => $country) {
            if ($key === $all_selection) {
                $selected = "SELECTED";
            }
            $html .= "<option value='{$key}' {$selected}>{$country}</option>";
            $selected = NULL;
        }
    }
    $html .= "</select>";
    return $html;
}