How to convert Object into Array in PHP?

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.

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →