📜  stdclass 到数组 - 任何代码示例

📅  最后修改于: 2022-03-11 14:55:50.055000             🧑  作者: Mango

代码示例3
$person = new stdClass();
$person->firstName = "Taylor";
$person->age = 32;

//Convert Single-Dimention Object to array
$personArray = (array) $person;

//Convert Multi-Dimentional Object to Array
$personArray = objectToArray($person);
function objectToArray ($object) {
    if(!is_object($object) && !is_array($object)){
        return $object;
    }
    return array_map('objectToArray', (array) $object);
}