배열 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년 전
좋은 팁 감사합니다~
게시판 목록
그누4 팁자료실
그누보드4와 관련된 팁을 여러분들과 함께 공유하세요.
나누면 즐거움이 커집니다.
나누면 즐거움이 커집니다.
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 3109 |
gstaron
|
12년 전 | 4784 | |
| 3108 |
|
12년 전 | 6798 | |
| 3107 | 12년 전 | 6831 | ||
| 3106 |
|
12년 전 | 8213 | |
| 3105 | 12년 전 | 6275 | ||
| 3104 | 12년 전 | 4791 | ||
| 3103 |
|
12년 전 | 4868 | |
| 3102 | 12년 전 | 3948 | ||
| 3101 | 12년 전 | 6981 | ||
| 3100 | 12년 전 | 6034 | ||
| 3099 | 12년 전 | 9972 | ||
| 3098 | 12년 전 | 3676 | ||
| 3097 |
lainfox
|
12년 전 | 4455 | |
| 3096 |
|
12년 전 | 10423 | |
| 3095 | 12년 전 | 4445 | ||
| 3094 | 12년 전 | 5104 | ||
| 3093 |
하늘바람구름
|
12년 전 | 4290 | |
| 3092 |
|
12년 전 | 8893 | |
| 3091 |
|
12년 전 | 9324 | |
| 3090 |
|
12년 전 | 6551 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기