当前位置: 首页 > 后端技术 > PHP

查询构造器结果--对象数组转换方法

时间:2023-03-29 14:16:09 PHP

一个小例子方法.../***数组转换对象**@param$earray*@returnobject|void*/publicfunctionarrayToObject($e){if(gettype($e)!='array')返回;foreach($eas$k=>$v){if(gettype($v)=='array'||getType($v)=='object')$e[$k]=(object)$this->arrayToObject($v);}返回(对象)$e;}/***对象转换数组**@param$eStdClassobjectExample*@returnarray|void*/publicfunctionobjectToArray($e){$e=(array)$e;foreach($eas$k=>$v){if(gettype($v)=='resource')返回;if(gettype($v)=='object'||gettype($v)=='array')$e[$k]=(array)$this->objectToArray($v);}返回$e;}result数组转换为object对象为数组