How to Convert Object into Array in PHP?
Hi Developer,
In this short tutorial, we will share the quick and straightforward way to php convert object to array. This post will give you a simple example of convert stdclass object to array in php. If you have a question about php object to array convert then I will give a simple example with a solution. Here you will learn php convert object to array example
Whenever you need to convert object to array in your php project then you can do that using (array). It is a pretty simple example to convert php object into array that way you can use array. So, let's see the following example.
Example:
<?php
class MyClass {
}
$myObject = new MyClass;
$myObject->id = 100;
$myObject->title = "posts";
$myObject->description = "this is posts";
$newArray = (array) $myObject;
print_r($newArray);
?>
Output:
Array
(
[id] => 100
[title] => posts
[description] => this is posts
)
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Get Previous Month from Date in PHP?
- How to Find Number from String in PHP?
- How to Get HTML Tag Value in PHP?
- PHP Curl Get Request with Parameters Example
- PHP Change File Name in Folder Example
- PHP Move File from One Folder to Another Example
- PHP Copy File from One Folder to Another Example
- PHP Multidimensional Array Search By Value Example
- How to Change Date Format in PHP?
- How to Convert Array to JSON in PHP?
- PHP CURL Post Request with Parameters Example
- PHP MySQL Column Sorting Example Tutorial
- How to Count Number of Files in a Directory in PHP?
- How to Find Day Name from Specific Date in PHP?