배열 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;
}
}
?>
<?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개
elancer
12년 전
좋은 팁 감사합니다~
게시글 목록
| 번호 | 제목 |
|---|---|
| 33785 | |
| 33781 | |
| 33776 | |
| 33761 | |
| 33753 | |
| 33751 | |
| 33749 | |
| 33731 | |
| 33706 | |
| 33694 | |
| 33690 | |
| 33683 | |
| 33674 | |
| 33672 | |
| 33662 | |
| 33655 | |
| 33608 | |
| 33605 | |
| 33587 | |
| 33581 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기