(1) method of the PHP object to the array (object to array):
/**
* Object turn 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) method of PHP JSON character to array (json to array):
If it is a JSON string, you can convert the string to an array directly through 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 format to be decoded by JSON.
Assoc When this argument is TRUE, returns the result of an array (associative array), which defaults to false, and returns an object.
Articles that you may be interested in
- Summary of methods for using Curl post submission data and get access to Web page data in PHP
- How PHP converts a multidimensional array to a one-dimensional array
- PHP Gets the method of the first array cell value of the array
- PHP finds whether a value exists in the array (In_array (), Array_search (), array_key_exists ())
- Use PHP function memory_get_usage to get current PHP memory consumption to achieve program performance optimization
- JS converts object to string function code
- PHP Array function array_map () notes
- PHP addresses URL encoding problem functions UrlEncode (), UrlDecode (), Rawurlencode (), Rawurldecode ()