Computer Science, asked by ajaytak9278, 1 year ago

How to convert PHP array to JavaScript array?

Answers

Answered by Anonymous
0

\huge\red{Answer}

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