我有一个代码:
$surat_id = 'SB-1';
$opd = array(13, 14);
$opd_id = implode(',', $opd);
$ex = explode(',', $opd_id);
foreach ($ex as $key => $h) {
$data = array(
'surat_id' => $surat_id,
'opd_id' => $h,
);
}
print_r($data);
结果是:Array ( [surat_id] => SB-1 [opd_id] => 14 )
但是我想要的结果是:
Array ( [surat_id] => SB-1 [opd_id] => 13 )
Array ( [surat_id] => SB-1 [opd_id] => 14 )
我应该如何获得这个结果?
答案 0 :(得分:0)
尝试一下
$surat_id = 'SB-1';
$opd = array(13, 14);
$data = array();
foreach ($opd as $key => $h) {
$data1 = array(
'surat_id' => $surat_id,
'opd_id' => $h,
);
array_push($data,$data1);
}
echo'<pre>';print_r($data);die;