SimpleXML - Yankı / print_r farklı değerler döndürür

0 Cevap php

Ben PHP kullanarak bir json nesnesi bazı xml dönüştürmek çalışıyorum.

Bu çalışma olmalı, ama bazı tuhaf nedenle bu başarısız.

Birileri girdi sağlayabilir.

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

Bu kod aşağıdaki döndürür.

{"background":{"0":"000033"},
 "image":"0":"0210e849f02646e2f5c08738716ce7e8b3c1169112790078351021245495.jpg"},
 "caption":   {"0":"Frog"}}

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

echo $image['bgColor']; shows '000033'

Nasıl yerine print_r deyimi yankı deyimi gibi değerleri ayrıştırmak. Bunlar neden farklı?

0 Cevap