dongwo1914 2019-05-02 22:31
浏览 86
已采纳

如何在php中使用closure来填充数组?

I want to avoid this notation:

$transactionsRows = [];

foreach ($data['invoces'] as $key => $invoice) {
   $transactionsRows[] = array();
}

Could I use closure in php to fill like this:

$transactionsRows = closure_fill(/* HERE FILL ARRAY AND RETURN */);
  • 写回答

1条回答 默认 最新

  • donglaoping9702 2019-05-02 22:38
    关注

    You can by using this function: array_values($array)

    array_values()

    $transactionsRows = array_values($data)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?