title: How to make a function return an array in php?
body: <p>I have faced a problem in returning a multiple values from the database in an array because every time i run this code it returns only the first row from the database but not all the rows and here is my code:</p>
  
  <p>In classes.php:</p>
  
  <pre><code>class user{
      public function showwinners(){
          $query="SELECT points,memberid,uname FROM user ";
          $all_answers=array();
          if($query_run=mysql_query($query)){
              if(mysql_num_rows($query_run)==NULL){
                  return 0;
              }
              while($query_row=mysql_fetch_assoc($query_run)){
                  $one=$query_row['points'];
                  $two=$query_row['memberid'];
                  $three=$query_row['uname'];
                  if($one&gt;=1){
                      $first=$one;
                      $second=$three;
                      array_push($all_answers,['name'=&gt;$second,'points'=&gt;$first]);
                      return $all_answers;
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>and in showwinners.php:    </p>
  
  <pre><code>$userobj=new user();
  $arr=array();
  $arr=$userobj-&gt;showwinners();
  foreach ($arr as $key =&gt; $a) {
      if(isset($a['name']))
          echo $a['name'];
          if(isset($a['points']))
              echo $a['points'];
  }
  </code></pre>