Home > Backend Development > PHP Tutorial > Parsing PHP's method of converting objects into arrays (compatible with multi-dimensional array types)_PHP Tutorial

Parsing PHP's method of converting objects into arrays (compatible with multi-dimensional array types)_PHP Tutorial

WBOY
Release: 2016-07-21 15:04:23
Original
1188 people have browsed it

Copy code The code is as follows:

/**
* @author Script Home
* @date 2013-6-21
* @todo Convert the object into an array
* @param unknown_type $obj
* @return unknown
*/
function object_to_array($obj){
$_arr = is_object($obj) ? get_object_vars($obj) :$obj;
foreach ($_arr as $key=>$val){
$val = (is_array($val) || is_object ($val)) ? $this->object_to_array($val):$val;
$arr[$key] = $val;
}
return $arr;
}

That’s it.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327771.htmlTechArticleCopy the code as follows: /*** @author Script Home * @date 2013-6-21 * @todo Convert object into array * @param unknown_type $obj * @return unknown*/ function object_to_array($o...
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