Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1024577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:47:54+00:00 2026-05-16T11:47:54+00:00

I want to use php array for HTML select list. In this case it

  • 0

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 each country short country code.

The php array that I’m currently using looks like:

$wcr=array(
'Angola',
'Antigua & Barbuda',
'Armenia', 
'Austria',
'Azerbaijan', 
 .....
 );

The PHP page that using this array:

<select name="country"><option selected value=""> --------- 
<? $p=1;asort($wcr);reset($wcr);
while (list ($p, $val) = each ($wcr)) {
echo '<option value="'.$p.'">'.$val;
} ?>
</select>

The value should be short country code (something like ‘ES’, ‘US’, ‘AN’, …) instead of numbers that I have right now as a values in this form. That short country codes I will write in this same PHP array somewhere, if it’s possible.

How can I do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:47:55+00:00Added an answer on May 16, 2026 at 11:47 am

    Use foreach(), it’s the best function to loop through arrays

    your array should look like jakenoble posted

    <select name="country">
    <option value="">-----------------</option>
    <?php
    foreach($wcr as $key => $value):
    echo '<option value="'.$key.'">'.$value.'</option>'; //close your tags!!
    endforeach;
    ?>
    </select>
    

    I also made some minor adjustements to your html code. The first option in the list will be selected by default so no need to specify it 😉

    EDIT: I made some edits after reading your question again

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use an associative array with the PHP iterator: http://php.net/manual/en/class.iterator.php is it
I want to rewrite http://website.com/?slug=product_info.php&products_id=32 to http://website.com/product_info/32 and I use this code, add_filter('rewrite_rules_array','wp_insertMyRewriteRules'); add_filter('query_vars','wp_insertMyRewriteQueryVars');
I want to use PHP to replace javascript functions in HTML documents. For example:
I want to use the sharer.php popup to open the share dialog, but would
I want to use an access card reader with PHP. I am doing this
I am currently using various back-end services and I want to use PHP to
Simple question I guess, I want to use PHP to write an update to
I want use a single php file to handle all of my voting requests.
I use the PHP language for file upload and want to know that the
I want to use PDT to debug PHP with eclipse. I am using ubuntu

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.