无法更新多维数组中的值[关闭]

问题描述 投票:0回答:0

我有一个数组如下。我希望将

[form_id] => 79
的值更新为
[form_id] => 123
.

Array
(
    [directory_table-columns] => Array
        (
            [6433fed3e408d] => Array
                (
                    [id] => 20
                    [label] => Rank
                    [form_id] => 79
                )
            [6433ffa1bf847] => Array
                (
                    [content] => <a href="{site_url}/user/{Player:1}">{Player:1}</a>
                    [label] => Custom Content
                    [form_id] => 79
                )
...
...

下面是我的代码。

foreach ( $src_gravityview_directory_fields as $key1 => $value1 ) {
        foreach ( $value1 as $key2 => &$value2 ) {
            $value2['form_id'] = $dest_form_id;
        }           
}

但是

form_id
的值没有改变。我也尝试了下面但没有快乐。

foreach ( $src_gravityview_directory_fields as $key1 => $value1 ) {

    foreach ( $value1 as $key2 => $value2 ) {
        
        $value2[$key2]['form_id'] = $dest_form_id;
    }           

}

我试过这个但它导致了无限循环。

php wordpress multidimensional-array
© www.soinside.com 2019 - 2024. All rights reserved.