title: How can I use a function inside a php foreach loop?
body: <p>I want to use a function inside my loop, in order to print my data in a nice format into my table.</p>
  
  <pre><code>$pdo = Database::connect();
  $sql = 'SELECT * FROM data ORDER BY id ASC';
  foreach ($pdo-&gt;query($sql) as $row) {
  
      function formatSizeUnits($bytes)
      {
          if ($bytes &gt;= 1073741824) {
              $bytes = number_format($bytes / 1073741824, 2).' GB';
          } elseif ($bytes &gt;= 1048576) {
              $bytes = number_format($bytes / 1048576, 2).' MB';
          } else {
              $bytes = '0 bytes';
          }
  
          return $bytes;
      }
  
  
      $bytes = $row['fileSize'];
      formatSizeUnits($bytes);
  
      echo('&lt;td&gt;'.$bytes.'&lt;/td&gt;');
  }
  </code></pre>
  
  <p>But now I get only the first entry of the database table. How can I get this work?</p>