SimpleXML - echo / print_r return different values
<p>I am trying to convert some xml into a json object using PHP.</p>

<p>This should be working, yet for some bizarre reason it is failing.</p>

<p>Could someone provide some input.</p>

<pre><code>// Loop Through images and return the right one.
$i = 1;
foreach($page-&gt;image as $image) {
    if ($i == $_GET['id']) {
         echo json_encode(array(
            'background' =&gt; $image['bgColor'],
            'image' =&gt; $image['source'],
            'caption' =&gt; $image['caption']
         ));
    }
    $i++;
}
</code></pre>

<p>This code returns the following.</p>

<pre><code>{"background":{"0":"000033"},
 "image":"0":"0210e849f02646e2f5c08738716ce7e8b3c1169112790078351021245495.jpg"},
 "caption":   {"0":"Frog"}}

print_r($image['bgColor']); shows 'SimpleXMLElement Object ( [0] =&gt; 000033 )'

echo $image['bgColor']; shows '000033'
</code></pre>

<p>How do I parse values like the echo statement instead of the print_r statement. Why are these different?</p>
