How to convert php object to array

藏色散人
Release: 2023-03-10 09:06:01
Original
4518 people have browsed it

How to convert php object to array: First create a PHP sample file; then use the code "$array = (array)$object;" to convert the object object into an array array.

How to convert php object to array

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How to convert php object to array?

Convert PHP object object to array

PHP part code

/* $object  object对象 数据信息
object(stdClass)#51 (4) {
  ["Message"] => string(2) "OK"
  ["RequestId"] => string(36) "4F15BC21-8548-4692-BC99-23ACF6A53ECB"
  ["BizId"] => string(20) "271812694197084716^0"
  ["Code"] => string(2) "OK"
}
*/
$array = (array)$object;  //核心代码
dump($array);
/* $array 数组  结果信息
array(4) {
  ["Message"] => string(2) "OK"
  ["RequestId"] => string(36) "B5D69728-FAF4-4C64-929D-B8A565CF44CB"
  ["BizId"] => string(20) "150010594197885250^0"
  ["Code"] => string(2) "OK"
}
*/
Copy after login

Recommended study: "PHP Video Tutorial"

The above is the detailed content of How to convert php object to array. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template