How to convert php array to js array
First use "json_encode" to convert the php array into a json string;
$arr = ['xiaoming', 'dahuang', 'xiaohua', 'zhangsan']; $arr = json_encode($arr);
Then use the php syntax in the js code to output the json string;
var arr = <?php echo $arr?>;
Finally, use the js variable to receive the json string output by the php code, and the js variable is the converted array.
Code:
Print result:
The above is the detailed content of How to convert php array to js array. For more information, please follow other related articles on the PHP Chinese website!