Not sure if this is a php or cakephp question. I am using cakephp ver3.1.3. I have a cakephp query object $query
that look like this when I call debug($query->toArray());
[
(int) 0 => object(App\Model\Entity\Customer) {
'id' => (int) 1,
'username' => 'asd',
'password' => '123',
'fullname' => 'asd',
'email_addr' => 'asd@gmail.com',
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Customers'
}
]
When I call json_encode($query)
, it looks like this;
[
{
"id": 1,
"username": "asd",
"password": "123",
"fullname": "asd",
"email_addr": "asd@gmail.com"
}
]
How do I process $query such that when I call json_encode($query)
, the output will look like this?
[
{
"email_addr": "asd@gmail.com"
}
]