Welcome Guest, Not a member yet? Register   Sign In
Looping multidimensional array just show one index while index is more than one
#1

Hi,
I've make a function to get messages and store it into an array and get attachments from each messages then make array for it also if attachment was exist.
in this case there is a message that has two attachment but when i looping and use dd(); it just show one attachment only.
here is my code:

Code:
    public function getTlMessages(){
        $mailbox = $this->getTlMailBox();
        $messages = $mailbox->getMessages();
        $messagelist = [];;
        $counter = 0;
        foreach ($messages as $message) {
            $counter++;
            $attachment = $message->getAttachments();
            $msg['id'] = $counter;
            $msg['gmailid'] = $message->getId();
            $msg['number'] = $message->getNumber();
            $msg['subject'] = $message->getSubject();
            $msg['attachment'] = array();
            foreach ($attachment as $attach){
                $attachlist['name'] = $attach->getFilename();
                $attachlist['subtype'] = $attach->getSubtype();
                $msg['attachment'] = $attachlist;
            }
            $messagelist[] = $msg;
        }
        dd($messagelist);
        return $messages;
    }


Here is the result:
it supposed to be two pdf file instead of one in "attachment"
[Image: Screen-Shot-2021-12-01-at-00-14-00.png]
Reply


Messages In This Thread
Looping multidimensional array just show one index while index is more than one - by zhikri - 11-30-2021, 10:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB