On 8/31/06, Adam Zey <azey@xxxxxx> wrote:
Javier Ruiz wrote: > Hi all, > > So I want to do... > > $xmlDatabase = new SimpleXMLElement($myXML); > foreach ($xmlDatabase as $oneTable) > { > if ($oneTable['name'] == 'two') > { > /// ---- HERE I WANT TO DELETE THE $oneTable NODE > unset($oneTable); // <-- and this doesn't work... > } > } > > > any ideas? > The answer is simple, everybody else seems to have missed it. foreach() makes a copy of the array before working on it. Changes made to $oneTable would obviously never affect the original. You're just unsetting a temporary variable that's going to be overwritten next time through the loop anyhow. You should have better luck with this code: $xmlDatabase = new SimpleXMLElement($myXML); foreach ($xmlDatabase as $key => $oneTable)
fwiw, In php5 you can do something like: foreach ($xmlDatabase as $key => &$oneTable) //note the & ------------------^^^^ unset($oneTable); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php