I need to assign unknown array keys and their values to strings.
The code I am using is:
$cart = $_SESSION['cart'];
$items = explode(',',$cart);
$qty = array();
foreach ($items as $item) {
$qty[$item] = $qty[$item] + 1;
}
print_r($qty);
The keys change and are not ordered. I do not know what the key or it's value may be. So as an example, I might have:
Array ( [2] => 5 [4] => 8 )
or in a different scenario, I might have:
Array ( [1] => 6 )
What those numbers represent is a product id (the key), and the quantity (the value of the key).
Can someone help me to assign these to a string? I have been reading all morning, and not making any progress.
Thank you!