0

在 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'];

有没有办法在循环中做到这一点,所以我不必硬编码节点名称?

4

1 回答 1

0

从一天更改为 &$day

foreach ($config->Week->children() as &$day){

但是,下一个更好

$children = $config->Week->children();
foreach ($children as &$day) {
        :
        :
}
$config->Week->setChildren($children); // setter

不能说英文很多,但我会传下来吗?

于 2013-07-12T22:39:27.987 回答