我的foreach元素每次都提供三个变量。
如何将其存储为多维数组。
我存储数组的代码是
foreach($parts as $part){
$filename = $filename;
$attachmentid = $attachmentid;
$filelocation = $filelocation;
$attachment = [
'filename' => $filename,
'attachmnetId' => $attachmentid,
'filelocation' => $filelocation
];
}
我的print_r($attachment)
仅显示最后一个foreach数组
答案 0 :(得分:0)
您需要添加[]
以为attachment
$attachment[] = [
'filename' => $filename,
'attachmnetId' => $attachmentid,
'filelocation' => $filelocation
];
答案 1 :(得分:0)
你有$附件只是一个字符串而不是一个数组
foreach($parts as $part){
$filename = $filename;
$attachmentid = $attachmentid;
$filelocation = $filelocation;
$attachment[] = [
'filename' => $filename,
'attachmnetId' => $attachmentid,
'filelocation' => $filelocation
];
}