배열 stdclass <-> array 변환

· 12년 전 · 5787 · 1
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;
}
}

?>
|

댓글 1개

좋은 팁 감사합니다~
댓글을 작성하시려면 로그인이 필요합니다.

그누4 팁자료실

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

+
제목 글쓴이 날짜 조회
12년 전 조회 5,615
12년 전 조회 1.2만
12년 전 조회 8,555
12년 전 조회 9,709
12년 전 조회 8,764
12년 전 조회 3,987
12년 전 조회 5,937
12년 전 조회 5,638
12년 전 조회 7,685
12년 전 조회 5,788
12년 전 조회 6,136
12년 전 조회 5,988
12년 전 조회 4,352
12년 전 조회 8,452
12년 전 조회 6,417
12년 전 조회 3,946
12년 전 조회 9,093
12년 전 조회 3,738
12년 전 조회 6,709
12년 전 조회 5,626