1

i have contorller

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);
}

and view

 <?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++;} ?>

How to combine array $data['detail'] and $data['bincard'] in one foreach view ?

Caconde
  • 4,177
  • 7
  • 35
  • 32

2 Answers2

1
$data['combined'] = array_merge($data['detail'],$data['bincard'])

See Combine two arrays

Josh Woodcock
  • 2,683
  • 1
  • 22
  • 29
0
foreach ($detail as $key => $value) {
    echo $value['inventorycode'];
    echo $bincard[$key]['bincard-array-key'];
}

Try like this it's working for me:

$data['new_array'] = array_merge($data['detail'],$data['bincard']);

and you have to use array_merge function to combine both arrays.

timiTao
  • 1,417
  • 3
  • 20
  • 34