Home > php教程 > php手册 > JSON 转 数组方法!

JSON 转 数组方法!

WBOY
Release: 2016-06-07 11:44:53
Original
1067 people have browsed it

用json传过来的数组并不是标准的array,所以需要用这个函数进行转换。
function object_array($array)<br> {<br>    if(is_object($array))<br>    {<br>     $array = (array)$array;<br>    }<br>    if(is_array($array))<br>    {<br>     foreach($array as $key=>$value)<br>     {<br>      $array[$key] = object_array($value);<br>     }<br>    }<br>    return $array;<br> }先json_decode再用~

PHP5.3 之后 可以传入json_decode($obj,true) 即可不用此函数!

AD:真正免费,域名+虚机+企业邮箱=0元

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