note 80968 modified in ref.simplexml by danbrown
| From: | danbrown@php.net | Date: | Mon, 18 May 2009 01:15:21 +0000 |
| Subject: | note 80968 modified in ref.simplexml by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155503@lists.php.net to get a copy of this message | ||
It doesn't seem to be documented anywhere, but you can refer to an element "value"
for the purpose of changing it like so:
<?php
$xml = simplexml_load_string('<root><number>1</number></root>');
echo $xml->asXml(). "\n\n";
$xml->number->{0} = $xml->number->{0} + 1;
echo $xml->asXml();
?>
echos:
<?xml version="1.0"?>
<root><number>1</number></root>
<?xml version="1.0"?>
<root><number>2</number></root>
However, this only works with a direct assignment, not with any of the other operators:
<?php
$xml = simplexml_load_string('<root><number>1</number></root>');
echo $xml->asXml(). "\n\n";
$xml->number->{0} += 1;
// Or:
$xml->number->{0}++;
echo $xml->asXml();
?>
Both of the above cases would result in:
<?xml version="1.0"?>
<root><number>1</number></root>
<?xml version="1.0"?>
<root><number>1<0/></number></root>
--was--
It doesn't seem to be documented anywhere, but you can refer to an element "value"
for the purpose of changing it like so:
<?php
$xml = simplexml_load_string('<root><number>1</number></root>');
echo $xml->asXml(). "\n\n";
$xml->number->{0} = $xml->number->{0} + 1;
echo $xml->asXml();
?>
echos:
<?xml version="1.0"?>
<root><number>1</number></root>
<?xml version="1.0"?>
<root><number>2</number></root>
However, this only works with a direct assignment, not with any of the other operators:
<?php
$xml = simplexml_load_string('<root><number>1</number></root>');
echo $xml->asXml(). "\n\n";
$xml->number->{0} += 1;
// Or:
$xml->number->{0}++;
echo $xml->asXml();
?>
Both of the above cases would result in:
<?xml version="1.0"?>
<root><number>1</number></root>
<?xml version="1.0"?>
<root><number>1<0/></number></root>
http://php.net/manual/en/ref.simplexml.php