title: Issues with putting a php associative array into javascript
body: <p>I am trying to put an php associative array into Javascript. I believe the array is already JSON encoded because its being inserted into a mongodb, but I keep getting undefined as my elements to the Javascript array. If I use json_encode($Data) I don't get undefined in my javascript elements but each element is only one letter. 
  ie: myArray[0] = {
  myArray[1] = M
  ...etc..</p>
  
  <p>PHP:</p>
  
  <pre><code>$Data = $_POST['data'];
  $Data = json_encode($Data);
  echo "&lt;script&gt;var myArray = $Data; &lt;/script&gt;";
  </code></pre>
  
  <p>Javascript:</p>
  
  <pre><code>&lt;script&gt;
  for(var i=0;i&lt;6;i++){
      alert(myArray[i]);
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>I have also tried to do it like this:</p>
  
  <pre><code>&lt;script&gt;
  var myArray = new Array();
  '&lt;?php foreach($Data as $key =&gt; $val){ ?&gt;'
     myArray.push('&lt;?php echo $val; ?&gt;');
  '&lt;?php } ?&gt;'
  &lt;/script&gt;
  </code></pre>
  
  <p>Please help!</p>
  
  <p>Update: var_dump from php array</p>
  
  <pre><code>{ ["Manufacturer"]=&gt; string(5) "Cisco" ["Device_Mdl"]=&gt; string(27) "Cisco" 
  ["Mgmt_Subnets"]=&gt; array(4) { ["Subnet_1"]=&gt; string(7) "Subnet1" 
  ["Subnet_2"]=&gt; string(6) "host 1" ["Subnet_3"]=&gt; string(8) "Subnet 2" 
  ["Subnet_4"]=&gt; string(6) "host 2" } ["Int_Info"]=&gt; array(2) { ["Type"]=&gt; 
  string(6) "Inband" ["Vlan"]=&gt; string(4) "4092" } ["VLANS"]=&gt; array(2) { 
  ["Int_ID"]=&gt; string(3) "tag" ["Int_Description"]=&gt; string(10) "base" } 
  ["Version"]=&gt; string(0) "" ["MGT_Address"]=&gt; string(11) "103.56.78.6" } 
  </code></pre>