How to convert a PHP object to an associative array?

Spread the love

Sometimes, we want to convert a PHP object to an associative array.

In this article, we’ll look at how to convert a PHP object to an associative array.

How to convert a PHP object to an associative array?

To convert a PHP object to an associative array, we can cast the object directly into an array.

For instance, we write

$array = (array) $yourObject;

to cast the $yourObject object directly to an associative array by putting (array) before $yourObject.

Conclusion

To convert a PHP object to an associative array, we can cast the object directly into an array.

Leave a Reply

Your email address will not be published.