PHP arrays into javascript arrays
<p>I am a bit confused here on how I implement an array into JS from PHP....</p>

<p>I'm doing this for testing - eventually I'll use long polling or websockets if they get highly supported but this is what I have:</p>

<pre><code>$get = mysql_query("SELECT x,y,sid FROM player_town WHERE uid='1'") or die(mysql_error());
$row = mysql_fetch_assoc($get);
$data = json_encode($row);
</code></pre>

<p>Further down the script I then put in the head:</p>

<pre><code>&lt;script&gt;var data = Array(&lt;? $data; ?&gt;)&lt;/script&gt;
&lt;script type="text/javascript" src="js.js"&gt;&lt;/script&gt;
</code></pre>

<p>But in js.js it says undefined but $data is set. This is the error:</p>

<pre><code>x is not defined
</code></pre>

<p>In js.js I did <code>alert(data[x]);</code> and I get undefined.</p>

<p>My json_encode looks like this:</p>

<pre><code>{"x":"283","y":"99","sid":"1"}
</code></pre>

<p>Any ideas?</p>
