title: Echo/return an array in php
body: <p>Im trying to query a database from a php file then return the results (userLOC of each row) to the calling Jquery function.</p>
  
  <p>Calling Jquery:</p>
  
  <pre><code>$.post(url, data, function (data) 
      {
          alert(data);
      })
  </code></pre>
  
  <p>relavent PHP:</p>
  
  <pre><code> $sql = "Select * from location";
   $result = mysql_query($sql);
   $stack = array();
   while($row = mysql_fetch_array($result))
    {
       array_push($stack, $row["userLOC"]);
    }
    return $stack;
  </code></pre>
  
  <p>The problem is that I cant return it correctly, if I "echo $stack" it does not work it says Im trying to convert the array to string. If I "echo $stack[0]" it will give me the first result in the array correctly so I know the values are being stored correctly (as are $stack[1], etc.) but this only sends the one value back. And if I "return $stack" as pictured nothing is alerted because nothing is echoed. How would I go about getting the whole array back so that I could iterate through and use them on the jquery side? </p>