I'm trying to get values from a PHP array in Javascript and populate a chart.
The problem is I believe that the javascript variable is not receiving the values.
I tried printing out the values, but nothing happens. Also it shows as object instead of an array, i don't know if it's suppose to be like that.
Any help will be greatful.
The PHP array when printed out:
print_r("<pre>");
print_r($exam_grades);
print_r("</pre>");
Array
(
[History] => 70
[Sociology] => 40
[Psychology] => 32
[Criminology] => 64
)
JS:
var exam_grades = <?php echo json_encode($exam_grades );?>;
alert(exam_grades.length); // this shows as undefined
for (var i = 0; i < exam_grades.length; i++) {
// do something
}