Home  >  Article  >  Backend Development  >  How to convert php object to array

How to convert php object to array

藏色散人
藏色散人Original
2021-06-02 10:23:144519browse

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"
}
*/

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!

Statement:
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