php - Last iteration values left in array -
if ($cart = $this->cart->contents()) { foreach ($cart $item){ $order_detail = array( 'res_id' =>$this->session->userdata('menu_id[]'), 'customer_id' =>$coustomers, 'payment_id' =>$payment, 'name' => $item['name'], 'productid' => $item['id'], 'quantity' => $item['qty'], 'price' => $item['price'], 'subtotal' => $item['subtotal'] ); } print_r($order_detail); exit;
when foreach
loop ends, last iteration value left. need values within array.
because order_detail
overwrite each time. use array instead of simple variable.
$order_detail = array(); if ($cart = $this->cart->contents()) { foreach ($cart $item){ $order_detail[] = array( 'res_id' =>$this->session->userdata('menu_id[]'), 'customer_id' =>$coustomers, 'payment_id' =>$payment, 'name' => $item['name'], 'productid' => $item['id'], 'quantity' => $item['qty'], 'price' => $item['price'], 'subtotal' => $item['subtotal'] ); } print_r($order_detail); exit;
Comments
Post a Comment