【发布时间】:2023-03-21 21:19:01
【问题描述】:
假设我有一个如下数组:
$settings = array(
"age" => "25",
"data" => array(
"name" => "John Dewey",
"zip_code" => "00000"
)
);
这是我的意见:
$target_directory = "data.name"; // targets $settings["data"]["name"]
$new_value = "Micheal"; // I want to change
// $settings["data"]["name"] with this value
我想要类似于以下内容:
$new_array = dont_know_what_to_do($target_directory, $new_value, $settings);
print_r($new_array) 应返回以下内容:
Array
(
[age] => 25
[data] => Array
(
[name] => Micheal,
"zip_code" => "00000"
)
)
更改应该是完全动态的,这意味着data.zip_code = "98985" 也应该仅将邮政编码值从 00000 更改为 98985,等等...
【问题讨论】:
-
你试过的代码在哪里?
-
我试图爆炸(".", $target_directory);但我不知道下一步该做什么?
-
只更新数据中的键?
-
试试我的答案。如果有效
-
你的意思是,“只有数据键被更新?”?如果是这样……那么是的。但是,如果我再向下一棵树,假设 data.name.first_name = $new_value。那么它应该只改变 ["data"]["name"]["first_name"] = $new_value;