不知道为什么,把数组序列化为json,然后存到redis(string类型)。然后再取出来反序列化为数组,就变成对象数组了
thinkPHP普通数组取值$arr['key'] 对象数组取值$arr->key
/**
* [std_class_object_to_array 将对象转成数组]
* @param [stdclass] $stdclassobject [对象]
* @return [array] [数组]
*/
function std_class_object_to_array($stdclassobject)
{
$_array = is_object($stdclassobject) ? get_object_vars($stdclassobject) : $stdclassobject; foreach ($_array as $key => $value) {
$value = (is_array($value) || is_object($value)) ? std_class_object_to_array($value) : $value;
$array[$key] = $value;
} return $array;
}
//调用这个函数,将其幻化为数组,然后取出对应值
function object_array($array)
{
if(is_object($array))
{
$array = (array)$array;
}
if(is_array($array))
{
foreach($array as $key=>$value)
{
$array[$key] = object_array($value);
}
}
return $array;
}