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])
Parameters:
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 ()