Converting an stdClass object to an array in PHP can be a tricky task, especially if the original object contains elements that are objects themselves. This question and answer provides a comprehensive solution to this problem.
The original question describes the following issue: the user is unable to convert an stdClass object into an array without deleting the object's rows. The user has tried several methods, such as using (array) $booking, json_decode($booking, true), and a custom function, but all of these methods have resulted in an empty array.
The solution to this problem lies in using a slightly different method: using json_encode and json_decode together to convert the object to and from JSON. This method allows for the preservation of the object's rows.
$array = json_decode(json_encode($booking), true);
The above is the detailed content of How to Convert a stdClass Object to an Array Without Losing Rows in PHP?. For more information, please follow other related articles on the PHP Chinese website!