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

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -