我想递归更新下面的数组,用一些其他值替换包含 [myKey] 键的数组的内容(比如说 [foo] => bar,[bar] => foo)。这没有使用引用,因为我已经有一些代码在工作,但我想重构它。
Array
(
[objects] => Array
(
[0] => Array
(
[somekey] => value
[items] => Array
(
[0] => Array
(
[myKey] => item1
)
[1] => Array
(
[myKey] => item2
)
)
)
[1] => Array
(
[otherKey] => other value
[items] => Array
(
[0] => Array
(
[myKey] => item3
)
[1] => Array
(
[myKey] => item4
)
)
)
[2] => Array
(
[myKey] => item5
)
)
)
我最后想要的如下。不要考虑我将如何决定使用哪些键/值,而只是考虑如何将它们添加到数组中......
Array
(
[objects] => Array
(
[0] => Array
(
[somekey] => value
[items] => Array
(
[0] => Array
(
[foo] => bar
)
[1] => Array
(
[bar] => foo
)
)
)
[1] => Array
(
[otherKey] => other value
[items] => Array
(
[0] => Array
(
[whatever] => value
)
[1] => Array
(
[foo1] => bar
)
)
)
[2] => Array
(
[bar1] => foo2
)
)
)
提前致谢!