剥去XML对象的对象状态,并保存其中包含的值


Strip an XML object of its object status, and save the value contained inside

我有一个对象,它包含一个数组,其中包含一个对象:

stdClass Object
(
    [path] => Array
        (
            [0] => Array
                (
                    [0] => SimpleXMLElement Object
                        (
                            [0] => 44.6451471575972
                        )
                )
        )
)

我需要把它变成这样:

stdClass Object
(
    [path] => Array
        (
            [0] => Array
                (
                    [0] => 44.6451471575972
                )
        )
)

基本上,我需要去掉那个对象,但要保存那个对象中的值。使用PHP,我该如何做到这一点?

编辑:这里是我用来创建数组的代码:

$xml = simplexml_load_file('/Users/jasonburton/Sites/walkabout/csv-importer/xml/'.$old_route_id.'.xml');
$nodes = $xml->xpath('/markers/line/*');
$json = new stdClass;
$json->path = array();
foreach($nodes as $node){       
  foreach($node->attributes() as $index=>$value){
    $values[] = $value;
    if(count($values) == 2){
      $json->path[] = array($values[0], $values[1]);
      unset($values);
      $values = array();
    }
  }         
}
print_r($json);

$value包含需要转换为值的SimpleXMLObject。

谢谢!

键入带字符串的强制转换$value:$values[]=(string)$value;