2015-11-02 75 views
0

我的foreach元素每次都提供三个变量。单个数组中的foreach元素存储

我如何将它作为多维数组存储。

我的代码存储阵列是

foreach($parts as $part){ 
    $filename = $filename; 
    $attachmentid = $attachmentid; 
    $filelocation = $filelocation; 
    $attachment = [ 
     'filename' => $filename, 
     'attachmnetId' => $attachmentid, 
     'filelocation' => $filelocation 
    ]; 
} 

print_r($attachment)只显示最后的foreach阵列

+1

foreach之后的前3行似乎很无用。 – Daan

回答

0

您需要添加[]作出数组attachment

$attachment[] = [ 
    'filename' => $filename, 
    'attachmnetId' => $attachmentid, 
    'filelocation' => $filelocation 
]; 
0

你有$附件只是一个字符串而不是数组

foreach($parts as $part){ 
$filename = $filename; 
$attachmentid = $attachmentid; 
$filelocation = $filelocation; 
$attachment[] = [ 
    'filename' => $filename, 
    'attachmnetId' => $attachmentid, 
    'filelocation' => $filelocation 
]; 
} 
相关问题