Array is an array. The disk array mode integrates the storage spaces of several disks to form a large single continuous storage space. array() is actually a language construct, usually used to define an array of direct quantities, but its usage is very similar to that of functions, so if you need to know more about array arrays, you can check the relevant manual, this article We share two tips with you.
1. PHP object to 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 directly convert the string into an array 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 The string in json string format to be decoded.
assoc When this parameter is TRUE, the result in the form of an array (associative array) will be returned. The default is false, and an object is returned.
Related recommendations:
Summary of commonly used PHP array (Array) functions
php function array_sum that returns the sum of all values in the array ()
php function array_sum() that returns the sum of all values in the array
The above is the detailed content of Object to Array Json to Array method. For more information, please follow other related articles on the PHP Chinese website!