PHP, Codeigniter
php 객체를 배열로, 배열을 객체로
beop07
2023. 3. 27. 18:45
php 객체(stdClass)를 배열로 변경하는 함수
function obj_to_arr($arr)
{
if (is_object($arr)) $arr = get_object_vars($arr);
return is_array($arr) ? array_map(__FUNCTION__, $arr) : $arr;
}
php 배열을 객체로(stdCLass) 변경하는 함수
function arr_to_obj($arr)
{
return is_array($arr) ? (object) array_map(__FUNCTION__, $arr) : $arr;
}
반응형