I'm developing a cart in PHP, however, when adding items to the array, I'm not getting it, I've tried it as follows:
if($this->session->userdata('cart')==true){
if(count($this->session->userdata('cart'))==0){
$i = 0;
} else {
$i = count($this->session->userdata('cart'))+1;
}
foreach($this->session->userdata('cart') as $value){
$data[$i] = array(
'cart_type' => ($this->input->post('stock_unity_push')) ? 'purchase' : 'order',
'product_id' => $this->input->post('product_id'),
'stock_purchase' => $this->input->post('stock_purchase'),
'stock_unity_push' => ($this->input->post('stock_unity_push')) ? $this->input->post('stock_unity_push') : '0',
'supplier' => $this->input->post('supplier'),
);
$i++;
}
} else {
$data[] = array(
'cart_type' => ($this->input->post('stock_unity_push')) ? 'purchase' : 'order',
'product_id' => $this->input->post('product_id'),
'stock_purchase' => $this->input->post('stock_purchase'),
'stock_unity_push' => ($this->input->post('stock_unity_push')) ? $this->input->post('stock_unity_push') : '0',
'supplier' => $this->input->post('supplier'),
);
}
The problem is that, every time I add a new item in the array, it replaces, and does not add. How can I just add items?
Note: I'm using codeigniter to render.