Php foreach元素存储在单个数组中
我的foreach元素每次提供三个变量 如何将其存储为多维数组 我存储数组的代码是Php foreach元素存储在单个数组中,php,arrays,foreach,Php,Arrays,Foreach,我的foreach元素每次提供三个变量 如何将其存储为多维数组 我存储数组的代码是 foreach($parts as $part){ $filename = $filename; $attachmentid = $attachmentid; $filelocation = $filelocation; $attachment = [ 'filename' => $filename, 'attachmnetId' =>
foreach($parts as $part){
$filename = $filename;
$attachmentid = $attachmentid;
$filelocation = $filelocation;
$attachment = [
'filename' => $filename,
'attachmnetId' => $attachmentid,
'filelocation' => $filelocation
];
}
我的print\u r$附件只显示最后一个foreach数组您需要添加[]来创建附件数组
您将$attachment作为字符串而不是数组
foreach($parts as $part){
$filename = $filename;
$attachmentid = $attachmentid;
$filelocation = $filelocation;
$attachment[] = [
'filename' => $filename,
'attachmnetId' => $attachmentid,
'filelocation' => $filelocation
];
}
foreach后面的前3行看起来很没用。
foreach($parts as $part){
$filename = $filename;
$attachmentid = $attachmentid;
$filelocation = $filelocation;
$attachment[] = [
'filename' => $filename,
'attachmnetId' => $attachmentid,
'filelocation' => $filelocation
];
}