不確定這是一個php還是cakephp問題。我正在使用cakephp ver3.1.3。我有一個CakePHP的查詢對象$query
看起來像這樣當我打電話debug($query->toArray());
從php對象中過濾掉一些元素
[
(int) 0 => object(App\Model\Entity\Customer) {
'id' => (int) 1,
'username' => 'asd',
'password' => '123',
'fullname' => 'asd',
'email_addr' => '[email protected]',
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Customers'
}
]
當我打電話json_encode($query)
,它看起來像這樣;
[
{
"id": 1,
"username": "asd",
"password": "123",
"fullname": "asd",
"email_addr": "[email protected]"
}
]
如何處理$查詢,這樣當我打電話json_encode($query)
,輸出會是這樣?
[
{
"email_addr": "[email protected]"
}
]
使用json_decode和json_encode函數。 – aldrin27