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 -

Python Tornado package error when running server -

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -