我有控制器
function showDetail($sono,$opnamedate,$warehouse,$stocktypeid){
$data['detail'] = $this->M_stock_opname->tampil_showDetail($sono,$opnamedate,$warehouse,$stocktypeid);
$data['bincard'] = $this->M_stock_opname->tampil_showBincard($year,$month,$data['detail']);
$this->load->view('stock_opname_showOpname_detail.php',$data);
}
并查看
<?php $no=1; foreach ($detail as $key) { ?>
<tr>
<td><?php echo $no; ?></td>
<td><?php echo $key->inventorycode ?> <input type="hidden" name="inventorycode[]" value="<?php echo $key->inventorycode ?>"></td>
<td><?php echo $key->inventoryname ?></td>
<td><input type="text" id="a" style="text-align:right" float="right" name="physicalquantity[]" value="<?php if(($key->physicalquantity) == '0'){echo "";}else{echo number_format($key->physicalquantity,0);}?>" onkeypress="return isNumberKey(event)"></td>
<td align="right"><?php if($key->approve == "1"){echo $dataquantity = '1';}else{ echo $dataquantity = '2';} ?> <input type="hidden" name="dataquantity[]" value="<?php echo $key->dataquantity ?>"></td>
<td align="right"><?php echo $key->physicalquantity - $key->dataquantity ?></td>
</tr>
<?php $no++;} ?>
如何在一个foreach视图中组合数组$ data ['detail']和$ data ['bincard']?
答案 0 :(得分:0)
$data['combined'] = array_merge($data['detail'],$data['bincard'])
答案 1 :(得分:0)
foreach ($detail as $key => $value) {
echo $value['inventorycode'];
echo $bincard[$key]['bincard-array-key'];
}
尝试这样,它为我工作:
$data['new_array'] = array_merge($data['detail'],$data['bincard']);
你必须使用array_merge
函数来组合两个数组。