Append element to object[arrays]?
<p>Append element to object[arrays] ?
I Have an $A</p>

<pre><code>SimpleXMLElement Object
(
    [books] =&gt; Array
    (
        [0] =&gt; SimpleXMLElement Object
        (
            [book] =&gt; Array
            (
                [0] =&gt; SimpleXMLElement Object
                (
                    [info] =&gt; SimpleXMLElement Object
                    (
                        [qty] =&gt; 12
                        [title] =&gt; C++
                    )

                )

                [1] =&gt; SimpleXMLElement Object
                (
                    [info] =&gt; SimpleXMLElement Object
                    (
                        [qty] =&gt; 21
                        [title] =&gt; PHP
                    )

                )

            )

        )

        [1] =&gt; SimpleXMLElement Object
        (
            [book] =&gt; SimpleXMLElement Object
            (
                [info] =&gt; SimpleXMLElement Object
                (
                    [qty] =&gt; 25
                    [title] =&gt; Java
                )

            )

        )

    )

)
</code></pre>

<p>I Want to return that new object with append [index]=>[$i][$j]</p>

<pre><code>  SimpleXMLElement Object
  (
      [books] =&gt; Array
      (
          [0] =&gt; SimpleXMLElement Object
          (
              [book] =&gt; Array
              (
                  [0] =&gt; SimpleXMLElement Object
                  (
                      [info] =&gt; SimpleXMLElement Object
                      (
                          [qty] =&gt; 12
                          [title] =&gt; C++
                          [index]=&gt;[0][0]
                      )

                  )

                  [1] =&gt; SimpleXMLElement Object
                  (
                      [info] =&gt; SimpleXMLElement Object
                      (
                          [qty] =&gt; 21
                          [title] =&gt; PHP
                          [index]=&gt;[0][1]
                      )

                  )

              )

          )

          [1] =&gt; SimpleXMLElement Object
          (
              [book] =&gt; SimpleXMLElement Object
              (
                  [info] =&gt; SimpleXMLElement Object
                  (
                      [qty] =&gt; 25
                      [title] =&gt; Java
                      [index]=&gt;[1][0]
                  )

              )

          )

      )
</code></pre>

<p>I have tried:</p>

<pre><code> foreach($object_xml as $key=&gt; $arr){ //&gt;&gt;&gt;$key =books
      foreach( $arr as $k =&gt;$value){ //$k = book
          foreach($value as $kk=&gt; $val){ //$kk=info
              $val-&gt;index = "$key&gt;&gt;&gt;$k&gt;&gt;&gt;$kk";
            //echo '&lt;pre&gt;';
            //print_r($val);
            //echo '&lt;/pre&gt;';

          }
        }
    }
/*
    echo '&lt;pre&gt;';
    print_r($object_xml);
    echo '&lt;/pre&gt;';
*/
    header('Content-type: text/xml');
    echo $object_xml-&gt;saveXml();
</code></pre>
