不知道为什么,把数组序列化为json,然后存到redis(string类型)。然后再取出来反序列化为数组,就变成对象数组了
thinkPHP普通数组取值$arr['key'] 对象数组取值$arr->key
1 /** 2 * [std_class_object_to_array 将对象转成数组] 3 * @param [stdclass] $stdclassobject [对象] 4 * @return [array] [数组] 5 */ 6 function std_class_object_to_array($stdclassobject) 7 { 8 $_array = is_object($stdclassobject) ? get_object_vars($stdclassobject) : $stdclassobject; 9 10 foreach ($_array as $key => $value) { 11 $value = (is_array($value) || is_object($value)) ? std_class_object_to_array($value) : $value; 12 $array[$key] = $value; 13 } 14 15 return $array; 16 }
//调用这个函数,将其幻化为数组,然后取出对应值 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; }