Home >Backend Development >PHP Tutorial >Convert PHP object to array_PHP tutorial

Convert PHP object to array_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:32:17862browse

Convert PHP object to array

Json or xml will be used to call data across platforms in the project. Need to convert json and xml objects into arrays. Just use the following function



/**
 * 
 * 把对象转成数组
 * @param $object 要转的对象$object 
 */
function objectToArray($object){  
	
	$result = array();  
	
	$object = is_object($object) ? get_object_vars($object) : $object;  
	
	foreach ($object as $key => $val) {  
		
		$val = (is_object($val) || is_array($val)) ? objectToArray($val) : $val;  
		
		$result[$key] = $val;  
	}  
	
	return $result;  
}


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/755782.htmlTechArticleConvert PHP objects into array projects to call data across platforms, json or xml will be used. Need to convert json and xml objects into arrays. Just use the following function /** * * Convert the object into an 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