How to convert php object into array
Aug 05, 2020 am 11:46 AMHow to convert PHP objects into arrays: 1. Use the encapsulated custom function and pass in the object. The code is [$array[$key] =$this->object_array($value)]; 2. Use the system function to convert, the code is [$arr=json_decode()].
Method to convert php object into array:
1. Encapsulate custom function and pass in object
public function object_array($object) { if(is_object($array)) { $array = (array)$array; } if(is_array($array)) { foreach($array as $key=>$value) { $array[$key] =$this->object_array($value); } } return $array; }
2. Use system function conversion
$arr=json_decode(json_encode($object),true); var_dump($arr);
Related video recommendations: PHP programming from entry to proficiency
The above is the detailed content of How to convert php object into array. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
