I am having the Following code:
$counter = $total_amt = 0;
$data = "";
$address = array(
'name' => filter_var($_POST["cust_name"], FILTER_SANITIZE_STRING),
'contact' => filter_var($_POST["cust_contact"], FILTER_SANITIZE_NUMBER_INT),
'pincode_id' => filter_var($_POST["cust_pincode"], FILTER_SANITIZE_NUMBER_INT),
'address' => filter_var($_POST["cust_address"], FILTER_SANITIZE_STRING),
'landmark' => filter_var($_POST["cust_landmark"], FILTER_SANITIZE_STRING),
'state_id' => filter_var($_POST["cust_state"], FILTER_SANITIZE_STRING),
'city_id' => filter_var($_POST["cust_city"], FILTER_SANITIZE_STRING)
);
foreach ($_SESSION["cart_item"] as $item)
{
if($counter < 1)
{
$data = array(
'item' => $item['id'],
'quantity' => $item["quantity"],
'price' => $item["price"]
);
}
elseif($counter >= 1)
{
$data = array(
'item' => $item['id'],
'quantity' => $item["quantity"],
'price' => $item["price"]
);
$data[] = $data;
}
$total_amt = $total_amt + $item["final_price"];
$counter ++;
}
I am getting following output of the code:
Array
(
[item] => 3
[quantity] => 1
[price] => 810
[0] => Array
(
[item] => 3
[quantity] => 1
[price] => 810
)
)
I am expecting this kind of O/P
Array
(
[0] => Array
(
[item] => 2
[quantity] => 2
[price] => 670
)
[1] => Array
(
[item] => 3
[quantity] => 1
[price] => 810
)
)
What's happening is i have two products added in cart using php sessions. I want to add that session variable to and array and then store it in database using serialize function. But, i am not able to store the variables in array format as shown above.
I have even tried the array_merge() function and othe logics but none is giving me this output. Can anyone help me out with this logic. Thanks in advance _/_
$datafor both arrays.