php - How to Input Joint Array in Codeigniter?

one text

how can I enter the invoice_no into add_sale_detail, like I entered it into add_sale, This code for add_sale_detail :

public function add_sale_detail($post) 
    {
        $result = array();
            foreach ($post['product'] as $key => $val) {
                $result[] = array(
                    'invoice' => $this->invoice_no(),
                    'product' => $post['product'][$key],
                    'serial_num' => $post['serial'][$key],
                    'price' => $post['price'][$key],
                    'qty' => $post['qty'][$key],
                    'total' => $post['total'][$key]
                );      
            } 
        $this->db->insert_batch('sale_detail', $result);
    }

and I put the invoice_no in add_sale, its worked like this :

public function add_sale($post)
    {
        $params = array(
            'invoice' => $this->invoice_no(),
            'customer_id' => $post['customer'] == '' ? null : $post['customer'],
            'sales_id' => $post['sales'],
            'qty_sum' => $post['qty'],
            'total_sum' => $post['total'],
            'cash' => $post['cash'],
            'note' => $post['note'],
            'date' => $post['date'],
            'user_id' => $this->session->userdata('userid')
        );
        $this->db->insert('sale', $params);
    }

Source