0
我有多個鍵的對象在PHP的數組:PHP不能使用類型stdClass的的對象作爲陣列錯誤
Array
(
[0] => stdClass Object
(
[ID] => 4983
[post_id] => 56357
[date] => 2016-06-04 23:45:28
)
[1] => stdClass Object
(
[ID] => 4982
[post_id] => 56241
[date] => 2016-06-04 22:58:27
)
)
然後我使用以下改變日期格式:
foreach($results as &$row) {
$row['date'] = ago($row['date']);
}
但是我一直在收到Cannot use object of type stdClass as array
錯誤。
對此爲何發生的任何建議?
您需要使用'mysql_fetch_ *'函數獲取數據。你的'$ result'變量是一個'resource'(http://php.net/manual/en/function.mysql-query.php) –
你根本不應該得到那個結果。你是json_encoding一個mysql結果句柄,它不是**結果本身。 –
我刪除了問題的頂部。這是一個簡化版本。只要說我得到的結果,我需要替換'日期'。 –