How to convert an object to an array with PHP?

Spread the love

Sometimes, we want to convert an object to an array with PHP.

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

How to convert an object to an array with PHP?

To convert an object to an array with PHP, we can cast it to an array directly.

For instance, we write

$array = (array) $object;

to convert the $object object to an array with (array).

Conclusion

To convert an object to an array with PHP, we can cast it to an array directly.

Leave a Reply

Your email address will not be published.