0

againAnotherChild is an object now how can i put the data from it to an array.

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;
    }

if i do print_r($againAnotherChild) this is what i get which updates after each iteration

SimpleXMLElement Object ( [0] => uint8 ) SimpleXMLElement Object ( [0] => uint8 ) SimpleXMLElement Object ( [0] => enum ) SimpleXMLElement Object ( [0] => uint8 ) SimpleXMLElement Object ( [0] => enum ) SimpleXMLElement Object ( [0] => uint8 ) SimpleXMLElement Object ( [0] => firmware ) SimpleXMLElement Object ( [0] => enum ) SimpleXMLElement Object ( [0] => enum ) SimpleXMLElement Object ( [0] => uint8 ) SimpleXMLElement Object ( [0] => enum )

------------------------Next Iteration--------------

SimpleXMLElement Object ( [0] => nodeid ) SimpleXMLElement Object ( [0] => uint8 ) SimpleXMLElement Object ( [0] => ipaddress ) SimpleXMLElement Object ( [0] => macaddress ) SimpleXMLElement Object ( [0] => enum ) SimpleXMLElement Object ( [0] => uint8 ) SimpleXMLElement Object ( [0] => uint16 ) SimpleXMLElement Object ( [0] => uint16 ) SimpleXMLElement Object ( [0] => uint16 ) SimpleXMLElement Object ( [0] => uint16 ) SimpleXMLElement Object ( [0] => enum ) SimpleXMLElement Object ( [0] => enum ) SimpleXMLElement Object ( [0] => uint16 ) SimpleXMLElement Object ( [0] => uint16 ) SimpleXMLElement Object ( [0] => uint16 ) SimpleXMLElement Object ( [0] => uint16 ) SimpleXMLElement Object ( [0] => enum )

How can i put these uint8,uint16 etc into an array that keeps updating till last iteration?

Peter VARGA
  • 4,780
  • 3
  • 39
  • 75

2 Answers2

1

The simple solution was just to type cast an object to certain data type

    $store = (array)againAnotherChildArray;

What i did in my code is this

                    $nodesWithValues = (array)$anotherChild->children();
                    foreach ($nodesWithValues as $key => $value)
                    {
                        //echo "$key : $value <br>";//CfgVer : uint8
                        var_dump($nodesWithValues);
                    }

problem solved by simple type casting :D

0

Are you asking about removing duplicates in array?

Would this help?

$againAnotherChildArray[$againAnotherChild->getName()] = $againAnotherChild->getName();

That should create something like hash map, eg set of tuples;

Dolfa
  • 796
  • 4
  • 21
  • The array is empty what for example $store [] = againAnotherChildArray[0]; but of course i cannot put values of an XML object in an array. – Muhammad Bilal Oct 23 '18 at 18:15