How to convert PHP array to JavaScript array?
Answers
Answered by
0
If you don't have PHP 5.2 you can use something like this:
function js_str($s) { return '"' . addcslashes($s, "\0..\37\"\\") . '"'; } function js_array($array) { $temp = array_map('js_str', $array); return '[' . implode(',', $temp) . ']'; } echo 'var cities = ', js_array($php_cities_array), ';';
HOPE IT HELPS YOU !!
Similar questions