PHP Object to Array (Object to Array), Json to Array (Json to Array) Method

Source: Internet
Author: User
Tags php json

PHP Object to Array (Object to Array), Json to Array (Json to Array) Method

(1) php object to array method (object to array ):

/*** Convert object to array */function object_to_array ($ obj) {$ _ arr = is_object ($ obj )? Get_object_vars ($ obj): $ obj; foreach ($ _ arr as $ key => $ val) {$ val = (is_array ($ val )) | is_object ($ val )? Object_to_array ($ val): $ val; $ arr [$ key] = $ val;} return $ arr ;}

(2) php Json character to array method (json to array ):

If it is a json string, you can directly use the json_decode function to convert the string into an array.

Json_decode (PHP 5 >=5.2.0, PECL json >=1.2.0)

Json_decode-accept a JSON string and convert it to a PHP variable

Mixed json_decode (string $ json [, bool $ assoc])


Json string to be decoded.

When this parameter is set to TRUE, assoc returns an array (associated array) result. The default value is false, and an object is returned.

Articles you may be interested in
  • Php converts a multi-dimensional array to a one-dimensional array
  • In php, we use the curl post method to submit data and the get method to obtain webpage data.
  • Convert an Object to a String function code in js
  • Use the PHP function memory_get_usage to obtain the current PHP memory consumption for program performance optimization.
  • Php method for obtaining the first array unit value of an array
  • Php searches for the existence of a value in the array (in_array (), array_search (), array_key_exists ())
  • PHP Array Function array_map () Notes
  • URL encoding functions such as urlencode (), urldecode (), rawurlencode (), and rawurldecode ()

Related Article

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