简体   繁体   English

如何使用闭包来填充 php 中的数组?

[英]How to use closure to fill array in php?

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:我可以在 php 中使用闭包来填充这样的:

$transactionsRows = closure_fill(/* HERE FILL ARRAY AND RETURN */);

You can by using this function: array_values($array)您可以使用此函数: array_values($array)

array_values()数组值()

$transactionsRows = array_values($data)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM