Modifying arrays in place that are stdClass arrays

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello, I have not had a lot of opportunity to deal with stdClass
objects in php.  This should be a simple one.  I have been plagued
with failure for far too many hours, so I bring it to the more
experienced.

I have $result = imap_fetch_overview(...) which returns a large
stdClass object, depending on the imap mail that I am reading.  I do
no think anyone need know anything about IMAP functions to help me on
this one.

Here is the result of the $result as a print_r()
http://pastebin.com/f4aee86ef

As you can see, there is one outer object, inside that are two iner
"parts" objects, the second "part" object has sub parts.  My goal is
to inject into the front of those, a new set of values.

     foreach ($structure->parts as $key => $val) {

          // Inject this to the replace the stdClass parts array
          $part_array[] = array('partnumber' => ($key + 1),
'part_object' => $val);

     }

So far, that works to add in two new items to the beginning of the
outer two objects.   I get something like this
[0] => Array
        (
            [partnumber] => 1
            [part_object] => stdClass Object
            .....

   [1] => Array
        (
            [partnumber] => 2
            [part_object] => stdClass Object
            .....

Now on item [1] in the above, there is a sub [part], containing 7
[parts] objects.  I want to make the same in place modifications to
those, adding in an item of [partnumber] and the key number I am at.

* I am going to do more to those added in values, but this distills it
down to my core issue.  In short, those parts need numbers, which are
then fed to another IMAP function to read out those specific parts of
an email. These objects can contain anywhere from 0 to a large number
of sub parts, depending on the complexity of the email, if it has
attachments, and if those attachments are also emails.

I have been playing around with this inside the main loop, but it puts
the partnumber in a place that is not correct.
          // There are sub parts
          if (count($val->parts) > 0) {
               foreach ($val->parts as $key2 => $val2) {
                    //$part_array[1] = array('partnumber' => ($key2 +
1), 'part_object' => $val2);
               }
          }

Thanks for any guidance.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux