Php 数组值在空foreach中循环后发生更改

Php 数组值在空foreach中循环后发生更改,php,arrays,loops,foreach,Php,Arrays,Loops,Foreach,我从SQL查询中创建了一个数组$export,稍后对其进行了一点格式化。阵列现在看起来像这样(这是整个阵列的最后两个阵列) 但是如果我现在把它放到这个foreach循环中,只打印嵌套的price数组 foreach ($export as $attribute){ echo '<pre>'; echo print_r($attribute['price']); echo '</pre>'; } 请注意,最后一个数组中的id

我从SQL查询中创建了一个数组$export,稍后对其进行了一点格式化。阵列现在看起来像这样(这是整个阵列的最后两个阵列)

但是如果我现在把它放到这个foreach循环中,只打印嵌套的price数组

foreach ($export as $attribute){
        echo '<pre>';
        echo print_r($attribute['price']);
        echo '</pre>';
}
请注意,最后一个数组中的id_属性与源$export数组中的id_属性不同。这只会发生在整个数组的最后一个嵌套数组中


我不知道为什么会发生这种情况,因此非常感谢您的帮助。

问题是什么?最后一个“id_属性”的问题是181,而不是原始数组的182。这听起来很奇怪,你能附加一些小的代码片段来复制它吗?请注意,输出中额外的
1
print\r
的默认行为,它会立即输出变量。Ommit
echo
或使用
true
作为缓冲输出的第二个参数,
echo print\r($data,true)
tyr要回显子数组的$key,foreach($key=>$attribute导出)我们需要在回显/打印部分之前查看与
$export
交互的任何代码。
foreach ($export as $attribute){
        echo '<pre>';
        echo print_r($attribute['price']);
        echo '</pre>';
}
Array
(
    [0] => Array
        (
            ["id_attribute"] => 181
            ["id_custo_group"] => "1"
            ["price_impact"] => 4099.173554
        )

    [1] => Array
        (
            ["id_attribute"] => 181
            ["id_custo_group"] => "2"
            ["price_impact"] => 4099.173554
        )

    [2] => Array
        (
            ["id_attribute"] => 181
            ["id_custo_group"] => "3"
            ["price_impact"] => 4099.173554
        )

)
1
Array
(
    [0] => Array
        (
            ["id_attribute"] => 182
            ["id_custo_group"] => "1"
            ["price_impact"] => 4099.173554
        )

    [1] => Array
        (
            ["id_attribute"] => 182
            ["id_custo_group"] => "2"
            ["price_impact"] => 4099.173554
        )

    [2] => Array
        (
            ["id_attribute"] => 181
            ["id_custo_group"] => "3"
            ["price_impact"] => 4099.173554
        )

)
1