donglan7594 2010-01-29 15:36
浏览 103
已采纳

PHP:警告:array_merge_recursive():检测到递归

I have a list of arrays (unknown amount), I need to merge all of them recursively.

So what I did what create an array of all of those arrays and pass them into this function:

function mergeMonth($array)
{
    foreach($array as $date_string => $inner_array)
    {
        if(isset($temp_inner_array))
        {
            $temp_inner_array = array_merge_recursive($temp_inner_array,$inner_array);
        }
        else
        {
            $temp_inner_array = $inner_array;
        }
    }

    return $temp_inner_array;
}

Most of the time this works just like I expected it to, but sometimes I get this error:

Warning: array_merge_recursive(): recursion detected in ... on line 89

Don't know why?

Any ideas?

Thanks!!

UPDATE

the structure is like this:

Array
(
    [sales] => 301.5
    [cost] => 
    [repairs] => 0
    [esps] => 0
    [margin] => 301.5
    [verified] => unverified
)

Which I then changed to:

Array
(
    [sales] => 301.5
    [cost] => 0
    [repairs] => 0
    [esps] => 0
    [margin] => 301.5
    [verified] => unverified
)

and that fixed the issue :)

Note anyone who can explain WHY my change fixed it, will get the accepted answer!

  • 写回答

1条回答 默认 最新

  • douhua1760 2010-01-29 16:00
    关注

    On possibility is that one array was referencing another one.

    Simple example

            $a = array
            (
                'cost' => null,
            );
            $b = array
            (
                'cost' => &$a['cost'], // appears as "[cost] => " 
                                       // because $a['cost'] is null
            );
    

    This results in an recursion.

    I just don't know what design would cause that to happen...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器