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

JSON 转 数组方法!

WBOY
WBOYOriginal
2016-06-07 11:44:531020browse

用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元

Statement:
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