怎么将PHP对象数组转换成普通数组

WBOY
Release: 2016-06-13 11:51:40
Original
1067 people have browsed it

如何将PHP对象数组转换成普通数组?

如何将PHP对象数组转换成普通数组?

?

  在利用jQuery EasyUI框架进行程序开发时,碰到前台将JSON格式数据传递到服务器后台,经php的json_decode函数转换成的数组由于为对象数组,php程序无法对数据进行正常处理的情况,为此需要开发一个PHP回调函数(objarray_to_array)将对象数组转换成普通数组。

?

/** * 对象数组转为普通数组 * * AJAX提交到后台的JSON字串经decode解码后为一个对象数组, * 为此必须转为普通数组后才能进行后续处理, * 此函数支持多维数组处理。 * * @param array * @return array */function objarray_to_array($obj) {    $ret = array();    foreach ($obj as $key => $value) {	if (gettype($value) == "array" || gettype($value) == "object"){            $ret[$key] =  objarray_to_array($value);	}else{	    $ret[$key] = $value;	}    }    return $ret;}
Copy after login

?

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!