배열 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와 관련된 팁을 여러분들과 함께 공유하세요.
나누면 즐거움이 커집니다.
나누면 즐거움이 커집니다.
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 3229 | 11년 전 | 4240 | ||
| 3228 |
평범한아빠
|
11년 전 | 9099 | |
| 3227 |
다케미카코
|
11년 전 | 5373 | |
| 3226 | 11년 전 | 10947 | ||
| 3225 | 11년 전 | 6109 | ||
| 3224 | 11년 전 | 7618 | ||
| 3223 |
다케미카코
|
11년 전 | 11662 | |
| 3222 | 11년 전 | 5181 | ||
| 3221 | 11년 전 | 5314 | ||
| 3220 | 11년 전 | 7091 | ||
| 3219 |
다케미카코
|
11년 전 | 4275 | |
| 3218 |
다케미카코
|
11년 전 | 4785 | |
| 3217 | 11년 전 | 4981 | ||
| 3216 |
다케미카코
|
11년 전 | 11450 | |
| 3215 | 11년 전 | 4872 | ||
| 3214 | 11년 전 | 7989 | ||
| 3213 | 11년 전 | 2656 | ||
| 3212 | 11년 전 | 5412 | ||
| 3211 | 11년 전 | 4824 | ||
| 3210 | 11년 전 | 10021 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기