標籤:comm string類 ram ges tor splay 取出 bsp nbsp
不知道為什麼,把數組序列化為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 }
View Code
//調用這個函數,將其幻化為數組,然後取出對應值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;}
php將對象數組轉成普通數組