Redeem object value

1

I own an object like this:

SimpleXMLElement Object
(
    [0] => 1bf7080ac1c04e4e9de924c0a7d9444d
)

But I can not redeem just the value of it. I've tried the following ways:

print_r($obj{0});
print_r($obj{'0'});
print_r($obj->{0});
print_r($obj->{'0'});
print_r($obj[0]);
print_r($obj['0']);
print_r($obj->[0]);
print_r($obj->['0']);

But I did not succeed!

    
asked by anonymous 04.10.2018 / 22:06

1 answer

1

You can use the current function that points to the index corrente of array , in this case the index 0 .

It would look like this:

current($obj);

Alternatively, you can convert to array :

$xml = simplexml_load_file('seu_arquivo.xml');    
$string = json_encode($xml);    
$array = json_decode($string);
    
04.10.2018 / 22:19