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

我有一个数组列表(未知数量),我需要递归地合并所有数组。</ p>

所以我做了什么创建所有这些数组的数组并将它们传递给这个函数:</ p>

  function mergeMonth($ array)
{

\ foreach($ array as $ date_string =&gt; $ inner_array)
{
if if(isset($ temp_inner_array))
{
$ temp_inner_array = array_merge_recursive($ temp_inner_array,$ inner_array);
}
else
{
$ temp_inner_array = $ inner_array;
}
}

返回$ temp_inner_array;
}
</ code> </ pre>

大部分时间 这有点像我预期的那样,但有时我得到这个错误:</ p>


警告:array_merge_recursive():
在第89行上检测到的递归< / p>
</ blockquote>

不知道为什么?</ p>

有什么想法吗?</ p>

谢谢!! </ p>

UPDATE </ h1>

结构如下:</ p>

  Array 

[sales] =&gt; 301.5
[费用] =&gt;

[repair] =&gt; 0
[esps] =&gt; 0
[margin] =&gt; 301.5
[已验证] =&gt; 未验证的

</ code> </ pre>

然后我改为:</ p>

  Array 

[sales] =&gt; 301.5
[费用] =&gt; 0
[维修] =&gt; 0
[esps] =&gt; 0
[margin] =&gt; 301.5
[已验证] =&gt;未验证\ n)
</ code> </ pre>

并解决了这个问题:)</ p>

请注意任何能够解释为什么我的更改修正了它的人都会得到 接受的答案!</ p>
</ div>

展开原文

原文

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!

douke6424
douke6424 来自@PvB-“如果没有关于你放入函数的数组的信息,就很难清除。你能举例说明导致警告的情况吗?或者描述你的”内部“数组的结构。”
10 年多之前 回复

1个回答



可能是一个数组引用了另一个数组。</ p>

简单示例< / strong> </ p>

  $ a = array 

'cost'=&gt; null,
);
$ b = array

' cost'=&gt;&amp; $ a ['cost'],//显示为“[cost] =&gt;”
//因为$ a ['cost']为空
);
</ code > </ pre>

这会导致递归。</ p>

我只是不知道哪种设计会导致这种情况发生...... </ p> \ n </ div>

展开原文

原文

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...

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐