Convert Object to Array in php
by z3n on Dec.29, 2010, under Coding
Problem:
How to convert a generic object into an array?
Solution:
I’ve wrote this to convert simple xml objects into array, works pretty good.
function toArray($obj) {
if (is_object($obj))
$obj = (array)$obj;
if (is_array($obj)) {
foreach ($obj as &$val)
$val = toArray($val);
} else { // if this is not an array so it's a string
$obj = (string)$obj;
}
return $obj;
}
No comments for this entry yet...