In the code below , i'm only able to get PHP arrays in javascript to work when I hard code the value . Is this the only way to get it to work, or is their a way to copy the entire PHP array into Javacript . Right now I'm tempted to just create a function chart() for each set of PHP array values. As in rather then writing function chart(a) , I might write function chart1() , function chart2(), function chart3()...   <?php            // Configuration            $hostname = 'host';            $username = 'user';            $password = 'pass';            $database = 'db';        $score = 'A' ;             $secretKey = myKey; // Change this value to match the value stored in the client javascript below         //$ValueD = 20 ; // this works             //$ValueA  ;            try {                $dbh = new PDO('mysql:host='. $hostname .';dbname='. $database, $username, $password);        echo Connected to database; // check for connection        //$dbh->exec(UPDATE Quiz1 SET $score = 1 WHERE Question = 1);  // THIS DOES NOT          //$dbh->exec(UPDATE Quiz1 SET B = 1 WHERE Question = 1); // THIS WORKS        /*        function getFruit($conn) {        $sql = 'SELECT A, B, C, D FROM Quiz1  WHERE QUESTION = 1';        foreach ($conn->query($sql) as $row) {           // print $row['B'] . \t;          //  print $row['A'] . \t;           // print $row['B] . \n;        global $ValueA , $ValueB , $ValueC , $ValueD  ;         $ValueA = $row['A'];// with this I can see the value , but it wont show up in the chart         $ValueB = $row['B'] ;         $ValueC = $row['C'] ;         $ValueD = $row['D'] ;         //echo $ValueA ;         }    }*/        function getFruit($conn) {        $sql = 'SELECT A, B, C, D , AnswerA , AnswerB, AnswerC, AnswerD FROM Quiz1  ';        foreach ($conn->query($sql) as $row) {           // print $row['B'] . \t;          //  print $row['A'] . \t;           // print $row['B] . \n;        global $ValueA , $ValueB , $ValueC , $ValueD , $AnswerA , $AnswerB, $AnswerC, $AnswerD ;        $ValueA[] = $row['A'];// with this I can see the value , but it wont show up in the chart         $ValueB[] = $row['B'] ;         $ValueC[] = $row['C'] ;         $ValueD[] = $row['D'] ;         $AnswerA[] = $row['AnswerA'];// with this I can see the value , but it wont show up in the chart         $AnswerB[] = $row['AnswerB'] ;         $AnswerC[] = $row['AnswerC'] ;         $AnswerD[] = $row['AnswerD'] ;         //echo $ValueA ;         }    }    //for ( i = 0 , i < $AnswerA.length , i++;){    //echo ($AnswerA[1])    //}        getFruit($dbh);         for ( $i = 0; $i <= 10; $i++){        //$h = ,;    $temp = (($AnswerA[$i]));    echo $temp . ,;    }    //print (array_values($AnswerA));    }    catch(PDOException $e)        {        echo $e->getMessage();        }    ?>        <head>             <!--Load the AJAX API-->        <script type=text/javascript src=https://www.google.com/jsapi></script>        <script type=text/javascript>        // load each var             function chart0(a){          //(array_values($array))         // var VaNum = parseFloat(Va);        var AnswerA1 = '<?php echo ($AnswerA[0]); ?>';        //var AnswerA = AnswerAt.split( );        var AnswerB1 = '<?php echo ($AnswerB[0]); ?>';        //var AnswerB = AnswerBt.split( );        var AnswerC1 = '<?php echo ($AnswerC[0]); ?>';        //var AnswerC = AnswerCt.split( );        var AnswerD1 = '<?php echo ($AnswerD[0]); ?>';        var AnswerAt = '<?php echo array_values($AnswerA); ?>';        var AnswerA = AnswerAt.split( );        var AnswerBt = '<?php echo array_values($AnswerB); ?>';        var AnswerB = AnswerBt.split( );        var AnswerCt = '<?php echo array_values($AnswerC); ?>';        var AnswerC = AnswerCt.split( );        var AnswerDt = '<?php echo array_values($AnswerD); ?>';        var AnswerD = AnswerDt.split( );        var Vat = '<?php echo array_values($ValueA); ?>';        var Va1 = '<?php echo ($ValueA[0]); ?>';        var Vb1 = '<?php echo ($ValueB[0]); ?>';        var Vc1 = '<?php echo ($ValueC[0]); ?>';        var Vd1 = '<?php echo ($ValueD[0]); ?>';         var VaNum = parseFloat(Va1);         var VbNum = parseFloat(Vb1);         var VcNum = parseFloat(Vc1);         var VdNum = parseFloat(Vd1);         /* var VbNum = Vb[a];          var VcNum = Vc[a];          var VdNum = Vd[a];*/    // Load the Visualization API and the piechart package.          google.load('visualization', '1.0', {'packages':['corechart']});          // Set a callback to run when the Google Visualization API is loaded.          google.setOnLoadCallback(drawChart);          // Callback that creates and populates a data table,          // instantiates the pie chart, passes in the data and          // draws it.          function drawChart($width,$height) {            // Create the data table.            var data = new google.visualization.DataTable();            data.addColumn('string', 'Topping');            data.addColumn('number', 'Slices');            data.addRows([              [AnswerA1, VaNum],              [AnswerB1, VbNum],              [AnswerC1, VcNum],              [AnswerD1, VdNum]              //crap , where not getting the number data here               //['Pepperoni', 2]            ]);            // Set chart options            var options = {'title': 'Quiz Results',                           'width':400,                           'height':300};            // Instantiate and draw our chart, passing in some options.            var chart = new google.visualization.PieChart(document.getElementById('chart_div' + a));            chart.draw(data, options);          }          }          chart0(0);        </script>
Have to hardcode Array values when using PHP arrays in JS
javascript;php