againAnotherChild是一个对象,现在我如何将其数据放入数组。
foreach($anotherChild->children() as $againAnotherChild) //child to
//childchildchild
{
// echo "Inside Again child Tag attributes<br>";
$againAnotherChildArray[] = $againAnotherChild->getName();
//print_r($againAnotherChild);
// foreach($this->$againAnotherChild[0] as $Storage)
// {
// $store = $Storage;
// //echo $store;
// }
echo $againAnotherChild[0]."<br>";
//echo "Storage".$store;
}
如果我执行print_r($ againAnotherChild),这就是每次迭代后更新的内容
SimpleXMLElement对象([0] => uint8)SimpleXMLElement对象( [0] => uint8)SimpleXMLElement对象([0] => enum) SimpleXMLElement对象([0] => uint8)SimpleXMLElement对象([0] =>枚举)SimpleXMLElement对象([0] => uint8)SimpleXMLElement对象([0] =>固件)SimpleXMLElement对象([0] =>枚举) SimpleXMLElement对象([0] =>枚举)SimpleXMLElement对象([0] => uint8)SimpleXMLElement对象([0] =>枚举)
------------------------下一个迭代-------------
SimpleXMLElement对象([0] => nodeid)SimpleXMLElement对象( [0] => uint8)SimpleXMLElement对象([0] => ipaddress) SimpleXMLElement对象([0] => macaddress)SimpleXMLElement对象 ([0] =>枚举)SimpleXMLElement对象([0] => uint8) SimpleXMLElement对象([0] => uint16)SimpleXMLElement对象( [0] => uint16)SimpleXMLElement对象([0] => uint16) SimpleXMLElement对象([0] => uint16)SimpleXMLElement对象( [0] =>枚举)SimpleXMLElement对象([0] =>枚举)SimpleXMLElement 对象([0] => uint16)SimpleXMLElement对象([0] => uint16) SimpleXMLElement对象([0] => uint16)SimpleXMLElement对象( [0] => uint16)SimpleXMLElement对象([0] =>枚举)
我如何将这些uint8,uint16等放入不断更新直到上次迭代的数组中?
答案 0 :(得分:1)
简单的解决方案是将对象类型转换为某些数据类型
$store = (array)againAnotherChildArray;
我在代码中所做的就是这个
$nodesWithValues = (array)$anotherChild->children();
foreach ($nodesWithValues as $key => $value)
{
//echo "$key : $value <br>";//CfgVer : uint8
var_dump($nodesWithValues);
}
问题通过简单的类型转换解决:D
答案 1 :(得分:0)
您是否要删除数组中的重复项?
有什么帮助吗?
$againAnotherChildArray[$againAnotherChild->getName()] = $againAnotherChild->getName();
这应该创建类似哈希图的东西,例如元组集;