dongtao4787 2011-09-08 07:52
浏览 121

在PHP中提取多维关联数组

I have an array in the following format:

Array
(
    [accountID] => Array
        (
            [0] => 412216
            [1] => 396408
            [2] => 522540
        )

    [mailBody] => Array
        (
            [0] => 'We are glad to have contact you'
            [1] => 'Thank you for your cooperation'
            [2] => 'One of our customer service representatives will contact you soon'
        )

    [mailAttachments] => Array
        (
            [0] => 'URL1'
            [1] => 'URL1'
            [2] => 'URL1'
        )

)

This array pulls some information from a mailing box. I would like to extract each accountID with equivalent mailBody and mailAttachments as well. Your response is highly appreciated.

  • 写回答

4条回答 默认 最新

  • drsc10888 2011-09-08 07:58
    关注

    Not beautiful but works (if I understand your purpose correctly):

    $mails = array();
    for ($i = 0, $cnt = count($array['accountID']); $i < $cnt; $i++) {
        $mails[] = array(
            'accountId'       => $array['accountID'][$i],
            'mailBody'        => $array['mailBody'][$i],
            'mailAttachments' => $array['mailAttachments'][$i]
        );
    }
    
    评论

报告相同问题?