SimpleXMLElement Object into array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rodeored

    SimpleXMLElement Object into array

    How do I put the value of an SimpleXMLElemen t Object into any array

    If $title is SimpleXMLElemen t Object ( [0] =Mother )

    how do I get "Mother" and put it in an array ? ;

    if I echo $title, it says "Mother" but if I put it in an array
    $myarray=array( $title);
    the array is Array ( [0] =SimpleXMLEleme nt Object ( [0] =>
    Mother ) )
    I don't want that I want
    Array ( [0] =>Mother) )
  • Jonathan Stein

    #2
    Re: SimpleXMLElemen t Object into array

    rodeored skrev:
    How do I put the value of an SimpleXMLElemen t Object into any array
    You might need to type cast the values (either implicit or explicit).
    if I echo $title, it says "Mother" but if I put it in an array
    $myarray=array( $title);
    It looks like you can directly cast $title to be an array:
    $myarray = (array)$title;

    - for other purposes you could also consider:
    $myarray = array( (string)$title );

    Regards

    Jonathan

    Comment

    • Michael Fesser

      #3
      Re: SimpleXMLElemen t Object into array

      ..oO(rodeored)
      >How do I put the value of an SimpleXMLElemen t Object into any array
      >
      >If $title is SimpleXMLElemen t Object ( [0] =Mother )
      >
      >how do I get "Mother" and put it in an array ? ;
      >
      >if I echo $title, it says "Mother" but if I put it in an array
      >$myarray=array ($title);
      >the array is Array ( [0] =SimpleXMLEleme nt Object ( [0] =>
      >Mother ) )
      >I don't want that I want
      >Array ( [0] =>Mother) )
      To access a SimpleXMLElemen t's content you have to cast it to a string.
      Sometimes this happens automatically, for example if you print it out or
      use any other function that accepts strings values, in cases like above
      you have to cast explicitly.

      Micha

      Comment

      Working...