Home > php教程 > PHP源码 > php向javascript传递数组的方法

php向javascript传递数组的方法

PHP中文网
Release: 2016-05-25 17:10:13
Original
1573 people have browsed it

PHP进行数组传值给javascript 此方法适用php5.2以上,php5.2以上自带该类。低于5.2的,请下载json类。json是一种数据传输格式 

php代码

$arr=一个数组;
$str=json_encode($arr);
echo "<input type=&#39;button&#39; name=&#39;insert&#39; value=&#39;Insert&#39; onClick=&#39;add($str)&#39;>";
Copy after login

js代码

function add(array)
{
alert(array.length);
//array就是$str数组
}
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template