S
Summercool
it seems quite strange that the array also prints out as element 1 in
the array in the following:
the second print_r() statement... printing out an array actually
prints out the first element...
Code:
========================================================================
<pre>
<?php
$xml =<<<XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<notes>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget this weekend!</body>
</note>
<note>
<to>Tove2</to>
<from>Jani2</from>
<heading>Reminder2</heading>
<body>Don't forget this weekend2!</body>
</note>
</notes>
XML;
$xml = new SimpleXMLElement($xml);
print_r($xml);
print_r($xml->note);
print_r($xml->note[0]);
print_r($xml->note[1]);
echo "\n\nlooping\n\n";
foreach($xml->note as $note)
print_r($note);
?>
Output:
========================================================================
SimpleXMLElement Object
(
[note] => Array
(
[0] => SimpleXMLElement Object
(
[to] => Tove
[from] => Jani
the array in the following:
the second print_r() statement... printing out an array actually
prints out the first element...
Code:
========================================================================
<pre>
<?php
$xml =<<<XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<notes>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget this weekend!</body>
</note>
<note>
<to>Tove2</to>
<from>Jani2</from>
<heading>Reminder2</heading>
<body>Don't forget this weekend2!</body>
</note>
</notes>
XML;
$xml = new SimpleXMLElement($xml);
print_r($xml);
print_r($xml->note);
print_r($xml->note[0]);
print_r($xml->note[1]);
echo "\n\nlooping\n\n";
foreach($xml->note as $note)
print_r($note);
?>
Output:
========================================================================
SimpleXMLElement Object
(
[note] => Array
(
[0] => SimpleXMLElement Object
(
[to] => Tove
[from] => Jani
=> Reminder
[body] => Don't forget this weekend!
)
[1] => SimpleXMLElement Object
(
[to] => Tove2
[from] => Jani2
[body] => Don't forget this weekend!
)
[1] => SimpleXMLElement Object
(
[to] => Tove2
[from] => Jani2
=> Reminder2
[body] => Don't forget this weekend2!
)
)
)
SimpleXMLElement Object
(
[to] => Tove
[from] => Jani
[body] => Don't forget this weekend2!
)
)
)
SimpleXMLElement Object
(
[to] => Tove
[from] => Jani
=> Reminder
[body] => Don't forget this weekend!
)
SimpleXMLElement Object
(
[to] => Tove
[from] => Jani
[body] => Don't forget this weekend!
)
SimpleXMLElement Object
(
[to] => Tove
[from] => Jani
=> Reminder
[body] => Don't forget this weekend!
)
SimpleXMLElement Object
(
[to] => Tove2
[from] => Jani2
[body] => Don't forget this weekend!
)
SimpleXMLElement Object
(
[to] => Tove2
[from] => Jani2
=> Reminder2
[body] => Don't forget this weekend2!
)
looping
SimpleXMLElement Object
(
[to] => Tove
[from] => Jani
[body] => Don't forget this weekend2!
)
looping
SimpleXMLElement Object
(
[to] => Tove
[from] => Jani
=> Reminder
[body] => Don't forget this weekend!
)
SimpleXMLElement Object
(
[to] => Tove2
[from] => Jani2
[body] => Don't forget this weekend!
)
SimpleXMLElement Object
(
[to] => Tove2
[from] => Jani2
=> Reminder2
[body] => Don't forget this weekend2!
)
[body] => Don't forget this weekend2!
)