title: Php push user array into users array and loop through users and user data (properties)
body: <p>I have a bunch of users into a database table (named "users"), each user with properties stored in the table's columns: id, username, first_name, last_name and so on.</p>
  
  <p>When a user is logged in, her/his data is retrieved from the database and displayed in a HTML table; for this purpose I have made the function (inside a functions.php file):</p>
  
  <pre><code>function user_data() {
    $users = array();
    $func_num_args = func_num_args();
    $func_get_args = func_get_args();
    if ($func_num_args &gt; 1) {
      unset($func_get_args[0]);
      $fields = '`' . implode( '`, `', $func_get_args) . '`';
    }
    $query = "SELECT $fields FROM users";
    $result = query($query);
    $col = mysqli_fetch_assoc($result);   
    array_push($users, $col);
  
    print_r($users);
    return $users;
  }
  </code></pre>
  
  <p>And then on the User's page: </p>
  
  <pre><code>$user_data = $user_data[0];
  echo "&lt;span&gt;Welcome, " . $user_data['first_name'] . " " .    $user_data['last_name'] . "!&lt;/span&gt;";
  </code></pre>
  
  <p>There are 2 users in the database yet the $users array contains only one user, as print_r($users) shows:</p>
  
  <pre><code>Array
  (
  [0] =&amp;gt; Array
      (
          [username] =&amp;gt; ajax
          [first_name] =&amp;gt; Razvan
          [last_name] =&amp;gt; Zamfir
          [email] =&amp;gt; razvan.zamfir80@gmail.com
          [telefon] =&amp;gt; 0743127315
          [oras] =&amp;gt; Bucuresti
          [adresa] =&amp;gt; Strada Alexandru Ipsilanti nr. 6, bloc 29E, sc. B, et. 3, ap. 83.
      )
  );
  </code></pre>
  
  <p>I need to loop through all the <strong>users</strong> and through <strong>each user's properties</strong> to display a <em>general table</em> that displays a user's <em>first name</em>, <em>last name</em> and and <em>Edit button</em> on each row.</p>
  
  <p>What am I doing wrong?</p>