PHP array and select list

后端 未结 4 1145
一整个雨季
一整个雨季 2020-12-16 20:47

I want to use php array for HTML select list. In this case it will be the list of countries but beside of country name that is listed in drop down list I need as a value of

4条回答
  •  执念已碎
    2020-12-16 21:16

    First make an associated array of country codes like so:

    $countries = array(
      'gb' => 'Great Britain',
      'us' => 'United States',
      ...);
    

    Then do this:

    $options = '';
    foreach($countries as $code => $name) {
      $options .= "\n";
    }
    $select = "";
    

提交回复
热议问题