Method 1:
Copy code The code is as follows:
//PHP stdClass Object to array
function object_array($array) {
if(is_object($array)) {
$array = (array)$array;
} if(is_array($array)) {
foreach($array as $key=>$ value) {
$array[$key] = object_array($value);
Method 2:
Copy code The code is as follows:
$array = json_decode(json_encode(simplexml_load_string($xmlString)),TRUE);
Method 3:
Copy code
The code is as follows:
function object2array_pre( &$object) { if (is_object($object)) { $arr = (array)($object); } else { $arr = &$object;
}
if (is_array($arr)) {
foreach($arr as $varName => $varValue){
$arr[$varName] = $this->object2array($varValue) ;
; If
is bad, you can replace it with the following:
Copy the code
The code is as follows:
function object2array(&$object) {
$ Object = JSON_DECODE (json_encode ($ Object), TRUE);
Return $ Object;
}
But the characteristics of JSON can only be targeted at UTF8, otherwise you must first transfer it. .
http://www.bkjia.com/PHPjc/767088.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/767088.html
TechArticleMethod 1: Copy the code as follows: //PHP stdClass Object to array function object_array($array) { if( is_object($array)) { $array = (array)$array; } if(is_array($array)) { forea...