在PHP脚本中,我想编辑一个节点及其属性。
<config>
<Week>
<Monday from="18:00:00" to="8:00:00">true</Monday>
<Tuesday from="18:00:00" to="8:00:00">true</Tuesday>
</Week></config>
foreach ($config->Week->children() as $day){
$day = $_POST["b_".$day];
$day['from'] = $_POST[$day."_from"];
$day['to'] = $_POST[$day."_to"];
}
这似乎不起作用。但这确实
$config->Week->Monday = $_POST['b_Monday'];
$config->Week->Monday['from'] = $_POST['Monday_from'];
$config->Week->Monday['to'] = $_POST['Monday_to'];
有没有办法在循环中执行此操作,因此我不必对节点名称进行硬编码?
答案 0 :(得分:0)
从一天更改为&amp; $ day
foreach ($config->Week->children() as &$day){
但是,下一个更好
$children = $config->Week->children();
foreach ($children as &$day) {
:
:
}
$config->Week->setChildren($children); // setter
英语不是很多,但我会传下去?