title: Reference Error array is not defined
body: <p>I tried the following code to retrieve values from the database and store them in a javascript array using php array. I tried using the following code, But it is returning me a Reference Error array is not defined.The code is as follows.</p>
  
  <pre><code>&lt;?php
  $con = mysql_connect("localhost","root","root");
  if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
  mysql_select_db("cerebra", $con);
  $sql="select name from details order by download desc limit 20";
  if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }
  $query=mysql_query($sql,$con);
  $names=array();
  $index=0;
  while($row=mysql_fetch_array($query)){
      $names[$index]=$row[0];
      $index++;
  }
  ?&gt;
  &lt;script&gt;
  var comp=new array();
  &lt;?php
   $i=0;
   foreach($names as $a){
          $i++;
          echo "comp[$i]='".$a."';\n";
  
          }
  ?&gt;
  for(i=0;i&lt;comp.length;i++)
              alert(comp[i]);
  
  &lt;/script&gt;
  </code></pre>