PHP Object goto Array (object to array), JSON to array (JSON to array) method
(1) PHP object to the array method (object to array):
/** * 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 convert the string to an array directly from the Json_decode function.
Json_decode (PHP 5 >= 5.2.0, PECL json >= 1.2.0)
Json_decode-accepts a JSON-formatted string and converts it to a PHP variable
Mixed Json_decode (String $json [, bool $assoc])
Parameters:
JSON string in JSON string format to decode.
Assoc When this argument is TRUE, returns the result of an array (associative array), which defaults to false and returns an object.
Articles you may be interested in
- How PHP converts multidimensional arrays to one-dimensional arrays
- How to use Curl's post submission data in PHP and get a summary of how to get Web page data
- JS converts object to string function code
- Use PHP function memory_get_usage to get the current PHP memory consumption to achieve program performance optimization
- How PHP gets the first array cell value of an array
- PHP finds whether a value exists in the array (In_array (), Array_search (), array_key_exists ())
- PHP Array function array_map () note
- PHP addresses URL encoding problem functions UrlEncode (), UrlDecode (), Rawurlencode (), Rawurldecode ()
http://www.bkjia.com/PHPjc/897780.html www.bkjia.com true http://www.bkjia.com/PHPjc/897780.html techarticle PHP Object-to-array (object-to-array), JSON-to-array (JSON-to-array) method (1) PHP Object-to-array method (object to Array):/** * object to array */function object _to_arra ...