PHP字符串中的JavaScript数组 [英] JavaScript array from PHP string

查看:71
本文介绍了PHP字符串中的JavaScript数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个拥有超过数千个值的应用程序。我想在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.

这篇关于PHP字符串中的JavaScript数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆