Working with Objects

I parse the text using the simplexml_load_file()function, as a result, I get something like:

Array
(
    [0] => AminoAcid Object
            [middle-name] => 
            [last-name] => 
            [author] => 
            [book-title] =>     
            [annotation] => 
            [p] =>     ...
            [keywords] =>  , , ,     
            [date] => 1869-70
            [lang] => ru
            [src-lang] => fr
            [translator] => 
        )
    [1] => AminoAcid Object
        (
           ... 
        )
    [2] => AminoAcid Object
        (
            ...
        )
    ...
)

Everything would be fine, but when outputting a string, the hyphen “-” in the tags interferes. For example:

$arry[0]->keywords;– outputs

$arry[0]->middle-name;– no output

How can I display text?


Answer 1

Fields of an object can be accessed like this:

echo $arry[0]->{'middle-name'};