title: How to foreach defined option start from selected value
body: <p>On Wordpress (note: this topic is not about Wordpress), first of all, I save a value to the database with a form. Then on another page I get a value from the database and I want to show it as &quot;selected&quot; in the option. I also want to show other options. Actually, (i think) there is a solution for this, but I couldn't find exactly how to search.
  I will explain briefly with an example. I hope it will be more understandable.</p>
  <p>Contents of the file where I saved the values ​​to the database:
  ...</p>
  <pre><code>$countries = array(
      'AF'=&gt;'AFGHANISTAN',
      'AL'=&gt;'ALBANIA',
      'DZ'=&gt;'ALGERIA',
      'AS'=&gt;'AMERICAN SAMOA',
  );
  
  //For example, if ALGERIA is selected, save it to the database as DZ.
  </code></pre>
  <p>...</p>
  <p>So far everything is fine.
  Here is the php file with the user profile from which I got the saved data:
  ...</p>
  <pre><code>// Define array again:
  $countries = array(
      'AF'=&gt;'AFGHANISTAN',
      'AL'=&gt;'ALBANIA',
      'DZ'=&gt;'ALGERIA',
      'AS'=&gt;'AMERICAN SAMOA',
  );
  //Get saved data (eg here returns DZ):
  $selected_countries = get_user_meta($user_id, $key);
  
  // Show values.
   ?&gt;
  &lt;select name=&quot;country&quot; id=&quot;country&quot;&gt;
  &lt;?php foreach($countries as $aabrr =&gt; $country){ ?&gt;
    &lt;option value=&quot;&lt;?php echo $aabrr ?&gt;&quot;&gt; &lt;?php echo $country ?&gt; &lt;/option&gt;
  &lt;?php } ?&gt;
  &lt;/select&gt;
  </code></pre>
  <p>...</p>
  <p>The problem is that what I want here is to start with the selected value (selected_countries). eg. if DZ is selected the option should start as ALGERIA. Of course, it doesn't make sense to write if for each value separately. There must be a short way around this but I couldn't find it.</p>