Pass PHP Array to Javascript
<p>Am trying to pass an array of values from PHP function to Javascript. Not sure if I am doing it correctly.</p>

<p>PHP:</p>

<pre><code>function toggleLayers(){
    for($i=0;$i&lt;$group_layer_row;$i++){
        $toggleArray=mb_convert_encoding(mssql_result ($rs_group_layer, $i, 0),"UTF-8","SJIS")."_".mb_convert_encoding(mssql_result ($rs_group_layer, $i, 1),"UTF-8","SJIS");
        return $toggleArray;
    }
}
</code></pre>

<p>JS:</p>

<pre><code>var myArray = [JSON.parse("&lt;?php echo json_encode($toggleArray); ?&gt;")];
    for(var i=0;i &lt; myArray.length; i++){
        if($myArray.getVisibility()==true){
            $myArray.getVisibility(false);
        }
    else{
        $myArray.getVisibility(true);
    }
}
</code></pre>

<p>SQL (for reference):</p>

<pre><code>$con = mssql_connect("myServer", "myUsername", myPassword");
$sql = "SELECT * FROM m_group_layer WHERE group_id=\"".$_SESSION["group_id"]."\" ORDER BY display_order";
$rs_group_layer = mssql_query ($sql, $con);   
$group_layer_row = mssql_num_rows($rs_group_layer);
</code></pre>

<p>I have been looking at some other similar questions, and the answers are either vague and/or there are a few thousand of them.</p>

<p>Would appreciate any help, also please try to explain as if you were writing a book called "Idiot's Guide to Passing PHP Arrays to JS"</p>

<p>Thanks for your help.</p>

<p><b>Edit:</b></p>

<p>Sorry, my question was very vague. Here's what I'm trying to do:</p>

<p>1.PHP Function gets all records from table into array(in this case they are map layers)</p>

<p>2.Javascript receives PHP array and loops through adding if clause to toggle layers.</p>

<p>Hope this makes it clearer.</p>
