Php shares an object (stdclass) to an Array Function

Source: Internet
Author: User
An excuse is often called and the returned content is a json string. The data type obtained after parsing the json string using the php function json_decode () is object (stdclass). This is an object, you can also obtain the content of the object, which can be obtained by using the object-attribute, but using arrays to process data, the following is an object (stdclass) converted to an array

An excuse is often called and the returned content is a json string. The data type obtained after parsing the json string using the php function json_decode () is object (stdclass). This is an object, you can also obtain the content of the object, which can be obtained by using the object-attribute, but using arrays to process data, the following is an object (stdclass) converted to an array

An excuse is often called and the returned content is a json string. The data type obtained after parsing the json string using the php function json_decode () is object (stdclass)

This is an object. To obtain the content, you can use the object-> attribute to obtain it. However, if you use arrays to process data, the following is a function for converting an object (stdclass) to an array.

function object_array($array){  if(is_object($array)){    $array = (array)$array;  }  if(is_array($array)){    foreach($array as $key=>$value){      $array[$key] = object_array($value);    }  }  return $array;} 

  

In fact, json_decode () needs to add the second parameter TRUE to parse the returned result as an array.

Stdclass is a reserved class of zend. It is an empty class with no content. All php classes inherit this class, that is, it is the parent class of all classes. When a class in PHP has no explicit parent class, it will be taken in by stdclass when it becomes an orphan class.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.