title: Return n value of array Function and list in while loop PHP
body: <p>I'm trying to show list of countries by the use of PHP function.</p>
  
  <p>Here's the database value that I'm retrieving on. <strong>(cropped)</strong></p>
  
  <p><img src="https://i.stack.imgur.com/s1p8E.png" alt="enter image description here"></p>
  
  <p>Here's the function that I'm retrieving the data.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>public function get_countries() {
  
      $list_country = array();
      $query = $this-&gt;db-&gt;prepare("SELECT name FROM country");
      $query-&gt;execute();
  
      while($r = $query-&gt;fetch(PDO::FETCH_ASSOC)) {
          $list_country[] = $r['name'];
      }
  
      return $list_country;
  }
  </code></pre>
  
  <p>Then here's the code where I echo all the data.</p>
  
  <pre><code>&lt;?php
      while (list($country) = $general-&gt;get_countries()) {
          echo $country;
      }
  ?&gt;
  </code></pre>
  
  <p>Unfortunately, it just all echo the same value over and over again.</p>
  
  <p><img src="https://i.stack.imgur.com/n6qxa.png" alt="enter image description here"></p>
  
  <p>Any solution for this? Like echo-ing all the data instead of the same data over and over again?</p>