如何在 cakephp 3 中使用键和值从数组中检索特定值

How to retrieve a specific value from an array with keys and values in cakephp3

我正在尝试访问查询后形成的数组中的特定值。

$query = $views->find('all');
$results = $query->all();
$data = $results->toArray();
$results = $query->toArray();

echo $results[0];

回显显示{'id':1, 'date':2016-07-27,'amount':30}

我只想从金额中得到30。我该怎么做?

直接访问数组的属性

echo $results[0]['amount']

php docs on arrays

获得单品:

$query = $views->findById($id);
//or
$query = $views->get($id);

echo $query->amount;

或者如果你想得到全部

$query = $views->find('all');

foreach ($query as $view) {
    echo $view->amount;
}