dpnzf48660 2017-10-14 19:50
浏览 99
已采纳

调用未定义的函数App \ Repositories \ array_build()

One of my colleagues wrote this code that builds an array for a chart:

$results = array_build(range($days - 1, 0), function ($k, $v) use ($dateFormat) {
            return [Carbon::today()->subDays($v)->format($dateFormat), [
                '0' => 0,
                '1' => 0
            ]];
        });

I just finished an upgrade from Laravel 5.2 to 5.3 and now get the following exception:

Call to undefined function App\Repositories\array_build()

I'm not exactly sure how his code works (hence I do not find the array_build method) and therefore cannot get it back working.

  • 写回答

2条回答 默认 最新

  • donglu953744 2017-10-14 20:05
    关注

    array_build() was dropped in version 5.3, which is why you can't use out of the box after your migration.

    array_build() helper is also removed from the framework as it’s no longer used anywhere in the core.

    You can get the function from the source:

    <?php
    function array_build($array, Closure $callback)
    {
        $results = array();
        foreach ($array as $key => $value)
        {
            list($innerKey, $innerValue) = call_user_func($callback, $key, $value);
            $results[$innerKey] = $innerValue;
        }
        return $results;
    }
    

    Note: the source is unofficial, there's no mention of dropping the function in the official migration doc

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧