我有一个包含数组的对象,该数组包含一个数组,其中包含一个对象:
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。
谢谢!
答案 0 :(得分:0)
使用字符串输入cast $ value:$ values [] =(string)$ value;