如何从数组栈中提取数组?

时间:2014-08-07 12:30:24

标签: php arrays imap

我有一组来自 imap_fetchstructure 的字符串数组。但我不能从字符串中提取字符串。我需要[filePath]的值,所以我傻了试过

echo [attachments:protected][filePath];

它根本不起作用。我对这种数组很新......这是数组的样本。

顺便说一下,这些线是从这里得到的:

$mailStructure = imap_fetchstructure($this->getImapStream(), $mailId, FT_UID);

哪个$this->getImapStream()来自班级ImapMailbox.php

IncomingMail Object ( 
    [id] => 2687 
    [date] => 2014-08-07 16:53:11 
    [subject] => test attc 
    [fromName] => Hello Kitty 
    [fromAddress] => hello@kitty.com 
    [to] => Array (
        [sales@hellokitty.com] => sales 
    ) 
    [toString] => sales 
    [cc] => Array ( ) 
    [replyTo] => Array (
        [hello@kitty.com] => Hello Kitty 
    ) 
    [textPlain] => testing for attachment 
    [textHtml] => testing for attachment
    [attachments:protected] => Array (
        [487540462265330294] => IncomingMailAttachment Object  ( 
             [id] => 487540462265330294 
             [name] => america_support_taks.jpg 
             [filePath] => /home/hellokitty/domains/hellokitty.com/public_html/email/inc/2687_487540462265330294_america_support_taks.jpg 
       ) 
   )
) 

1 个答案:

答案 0 :(得分:1)

答案很简单,方法可以在link you provided

中找到

附件是protected对象的IncomingMail属性(请参阅第558行),但进一步向下的几行是public方法getAttachments()(第567行) 。对象IncomingMailAttachment只有3个属性,所有属性都标记为public(第589行)。

$attachments = $mailStructure->getAttachments();

foreach ($attachments as $attachment) {
    // Array of IncomingMailAttachment objects
    echo $attachment->filePath;
}
相关问题