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
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments