Home php How to convert Object into Array in PHP?

How to convert Object into Array in PHP?

by Shahriar Sagor

Today now in this post i will show you how to convert an object into array in php. Whenever we need to convert an object to array in our php project then we can do this by using (array). So It is a very simple example to convert php object into an array that way we can do this by use array.

So, let’s see that on the following example.

Example:

$myObject = new MyClass;
$myObject->id = 100;
$myObject->title = "posts";
$myObject->description = "this is posts";
$newArray =  (array) $myObject;
print_r($newArray);

Read Also : How to clear cache from route, view, config and all cache data from application in Laravel

Thanks for read. I hope it help you. For more you can follow us on facebook.

close

You may also like