dtvfxzq3802 2015-12-22 22:29
浏览 614

在Laravel中使用array_get和动态键

I have a calculation like this in my code

foreach ($result as $point) {
  @$pointTotals[$point->date][$point->app_id] += $point->revenue;
 }

So I would like to avoid the @ symbol here and would like to use array_get instead. But will this support dynamic indexes and can I ue it like this ?

foreach ($result as $point) {
    $existingPoint = array_get($pointTotals, $point->date.$point->app_id, 0);
    $pointTotals[$point->date][$point->app_id] = $existingPoint + $point->revenue;
}

I am not getting any error here and so I think this is working fine. The thing here I can't test this I don't have any data and all are zeros. So I would like to confirm this will work fine with dynamic keys.

  • 写回答

0条回答 默认 最新

    报告相同问题?