I am using cakephp 3. Here I need sum a field, I already done it.
//mobile recharge total balance
$user_balance = $this->Users->find();
$user_balance
->select(['sum' => $user_balance->func()->sum('Users.balance')])
->first();
foreach ($user_balance as $balance) {
$this->set("user_balance", $balance->sum);
}
Here I have used first(), but why still it's returning an object. Is it possible to get direct sum or array. Here I don't want to use foreach.