/**
* 将数据库中取出单条数据转换成对象数组
* @param array $arrayList
*/
public function arrayToObject(array $array){
// 获取当前Model类名
$className = get_class($this);
// 实例化反射类,查看private权限用
//$reflectionClassAccess = new ReflectionProperty($className);
// 实例化发射类,修改属性用
$reflectionClass = new ReflectionClass($this);
foreach($array as $key => $value){
// 去掉下划线,下划线后的首字母转为大写
$keyNew = preg_replace('/_([A-Za-z0-9])/e',"strtoupper('$1')",$key);
if(property_exists($this,$keyNew)){
$methodSetName = 'set'.ucfirst($keyNew);
echo $methodSetName;
$function = $reflectionClass->getMethod($methodSetName);
$function->invoke($this,$value);
}
}
//var_dump($this);
unset($array);
return $this;
}
将数据库中取出单条数据转换成对象数组
最新推荐文章于 2021-05-20 16:34:34 发布