0

In a PHP script, I want to edit a node and its attributes.

<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"];
}

This does not seem to work. But this does

$config->Week->Monday = $_POST['b_Monday'];
$config->Week->Monday['from'] = $_POST['Monday_from'];
$config->Week->Monday['to'] = $_POST['Monday_to'];

Is there any way to do this in a loop so I don't have to hard-code the node names in?

user2367868
  • 97
  • 1
  • 8
  • Recommended reading: [How to get useful error messages in PHP?](http://stackoverflow.com/q/845021/367456) – hakre Jul 13 '13 at 07:53

1 Answers1

0

change from day to &$day

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

but, The next one is better

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

It can not be much English, but I will handed down?

Akira
  • 77
  • 2