问题描述
我正在开发一个拥有超过数千个值的应用程序。我想在JavaScript中创建一个动态数组。我正在使用AJAX来获取我的价值观。所以我必须从PHP创建一个字符串,它应该能够在JavaScript中从字符串转换为数组。
I am developing an application having more than thousands of values. I am trying to make a dynamic array in JavaScript. I'm using AJAX to get my values. So I have to create a string from PHP ,it should able to convert from string to array in JavaScript.
如何在PHP中创建一个可以转换为JavaScript中的数组?
How can I make a string in PHP that can be converted to array in JavaScript?
推荐答案
您正在寻找JSON和 json_encode():
You are looking for JSON and json_encode():
$string = json_encode($array);
字符串的内容将是用有效的javascript编写的数组。
The content of the string will be the array written in valid javascript.