Home >Backend Development >PHP Tutorial >PHP stdClass Object转array

PHP stdClass Object转array

WBOY
WBOYOriginal
2016-06-23 14:34:28778browse

PHP stdClass Object转array

用json传过来的数组并不是标准的array,所以需要用这个函数进行转换。

function object_array($array)
{
   if(is_object($array))
   {
    $array = (array)$array;
   }
   if(is_array($array))
   {
    foreach($array as $key=>$value)
    {
     $array[$key] = object_array($value);
    }
   }
   return $array;
}

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
Previous article:flex php 交互Next article:php 程序员