php array not showing up in javascript
<p>I created an array of values from data in MySQL. I then try to print it in Javascript but unfortunately it is not showing up.
Database has two cols: <code>gurtej</code> and <code>singh</code></p>

<pre><code>&lt;?php
require_once('config.php');
function readAttribute($connect){
    $resultArray=array();
    $sql="SELECT Attributename,Entityname FROM temp_data_attribute";
    $res=mysqli_query($connect,$sql);
    echo mysqli_num_rows($res);
    if(mysqli_num_rows($res)==0){
        return 0;
    }
    else{
        while($result=mysqli_fetch_array($res)){
            array_push($resultArray,$result[0]);
        }

        return $resultArray;
    }

}
?&gt;
&lt;html&gt;
&lt;body&gt;
&lt;script&gt;
    var jArray= &lt;?php
$resultArray=readAttribute($connect);
if($resultArray==0){
$resultArray=[];
}
echo json_encode($resultArray);?&gt;;
    var counter=&lt;?php echo count($resultArray);?&gt;;
    document.write(jArray[0]);

&lt;/script&gt;
&lt;?php
print_r($resultArray);
?&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>And when i try to print it in php using <code>print_r</code> this is the result.</p>

<blockquote>
  <p>Array ( [0] => gurtej [1] => singh )</p>
</blockquote>