Home > Backend Development > PHP Tutorial > 请教这是什么格式的数据

请教这是什么格式的数据

WBOY
Release: 2016-06-13 12:00:49
Original
999 people have browsed it

请问这是什么格式的数据?
a:4:{i:0;i:392;i:1;i:393;i:2;i:394;i:3;i:395;}
这是从数据库读出来的 。判断这个is_array 返回1 
说是个数组类型。这怎么才能转换成string或者给JS用呢。。谢谢

------解决方案--------------------
这是 php 序列化(serialize)数据
用 is_array 判断不可能返回 1
除非你做了反序列化(unserialize)

<br />$a = unserialize('a:4:{i:0;i:392;i:1;i:393;i:2;i:394;i:3;i:395;}');<br />echo '[' . join(',', $a) . ']';<br />//或<br />echo json_encode($a);<br />
Copy after login
[392,393,394,395]
就可以给 js 用了
------解决方案--------------------
1、序列化的数据先使用unserialize反序列化,得到原始的数组;
2、如果要将PHP里的数组传给JS用,那得转成JSON,然后JS访问JSON数据

Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template