Hello I\'m trying to pass several arrays from php to javascript. For some of them it works, for others not. I get an array of filenames and an array which contains the content o
Some general advice:
php.log
, error.log
, or httpd.log
or ask your server admin(s).Try using print_r() on your arrays to see if there's any difference in how they're structured. For example, just after setting the arrays in PHP:
print_r($fileArray);
print_r($listTextArray);
print_r($falseArray);
Rather than constructing the JS arrays via loops, try using the built-in json_encode() function instead. This both simplifies your PHP code and may cause more useful error messages when there are problems:
var filesArray=<?php json_encode($fileArray) ?>;
var falseArray=<?php json_encode($falseArray) ?>;
var textListArray=<?php json_encode($listTextArray) ?>;
you initiate
var textListArray=new Array(5);
but try to use
listTextArray
Use the same name and everything will be alright
The problem is already solved for you. Use json_encode
instead.
print('filesArray = '.json_encode($filesArray));
Note that json_encode
demands that your data is utf8 encoded. But you should do that already anyway.