배열 stdclass <-> array 변환 > 그누4 팁자료실

그누4 팁자료실

그누보드4와 관련된 팁을 여러분들과 함께 공유하세요.
나누면 즐거움이 커집니다.

배열 stdclass <-> array 변환 정보

배열 stdclass <-> array 변환

본문

stdClass -> Array 로 바꾸는 법.

<?php
 
function objectToArray($d) {
if (is_object($d)) {
// Gets the properties of the given object
// with get_object_vars function
$d = get_object_vars($d);
}
 
if (is_array($d)) {
/*
* Return array converted to object
* Using __FUNCTION__ (Magic constant)
* for recursive call
*/
return array_map(__FUNCTION__, $d);
}
else {
// Return array
return $d;
}
}
 
?>

Array -> stdClass


<?php
 
function arrayToObject($d) {
if (is_array($d)) {
/*
* Return array converted to object
* Using __FUNCTION__ (Magic constant)
* for recursive call
*/
return (object) array_map(__FUNCTION__, $d);
}
else {
// Return object
return $d;
}
}
 
?>
추천
0
  • 복사

댓글 1개

© SIRSOFT
현재 페이지 제일 처음으로