在 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'];
有没有办法在循环中做到这一点,所以我不必硬编码节点名称?