There is such an object:

var_dump($category); object(SimpleXMLElement)[109] public '@attributes' => array (size=2) 'id' => string '46' (length=2) 'parentId' => string '3' (length=1) public 0 => string '3D' (length=2) 

How can I get this property here ?:

  public 0 => string '3D' (length=2) 

    1 answer 1

    In general, in XML, names cannot begin with a number; accordingly, they cannot consist solely of a number.

    But try this design:

     var_dump($category->{0}); 

    or even more correct like this

     $x = 0; var_dump($category->$x); 
    • and not so graceful to do? $ categoryName = strval ($ category); - Sergalas
    • Is it possible to apply strval () to an object or an array? - Venta
    • This is not just an object that is SimpleXMLElement. For example, advice on my question toster.ru/q/359330 ? - Sergalas
    • Well, in that version and strval is not needed, check what the difference is $ categoryName = strval ($ category); echo $ categoryName; with the option echo $ category. Could you show what your XML looks like? - Venta
    • the one indicated by <category id = '46 'parent_id =' 3 '> 3D </ category> - Sergalas