Home / PHP Tips Generated By ChatGPT / Converting a PHP Object to an Array Convert an object to an associative array using get_object_vars(). Source Code $obj = (object) ['a' => 'Apple', 'b' => 'Banana']; $array = get_object_vars($obj); print_r($array); // Outputs the object properties as an array