0

My Array looks like this

Array ( 
  [title] => SimpleXMLElement Object ( 
    [0] => Car String
  ) 
)

And should look like this:

Array ( 
      title => Car String 
      ) 

I got this array by doing curl_exec a xml file and changed it with "new SimpleXMLElement". Every solution i could find didn't work.

So how can i transform the array? Or is there a more efficient way to get a xml with http header options?

RU NE
  • 15
  • 3

1 Answers1

0

When you build your array, you need to cast the SimpleXMLElement Object into the desired type. In your case you need to cast into a string element.

There is the simple way to do that :

$xmlString = "<element><title>Car String</title></element>";
$xml = new SimpleXMLElement($string);

$array = [
    'title' => (string)$xml->title;
];

or

$xmlString = "<element><title>Car String</title></element>";
$xml = new SimpleXMLElement($string);

$array = [
    'title' => $xml->title->__toString();
];
MrLizzard
  • 158
  • 9