That is entirely dependent on how you add and store that data. I for one don’t know the correlation of the colors. If I order a shirt, I don’t expect it to be added in three colors, I expect 1? If I order three shirts, then there should be a color assigned to each shirt.
<?php
class Product {
private $_itemId;
private $_size;
private $_color;
private $_price;
public function __construct($itemID, $size, $color, $price) {
$this->_itemId = $itemID;
$this->_size = $size;
$this->_color = $color;
$this->_price = $price;
}
public function getPrice() {
return $this->_price;
}
public function getOrderItem() {
return "Product Id: {$this->_itemId} Size Code: {$this->_size} Color Code: {$this->_color} Price: \${$this->_price}\n";
}
}
$order = [];
$order[] = new Product(1, 1, 3, 20);
$order[] = new Product(1, 1, 4, 20);
$order[] = new Product(1, 1, 2, 20);
$order[] = new Product(3, 3, 1, 50);
$total = 0;
$itemCount = 0;
foreach($order as $item) {
echo $item->getOrderItem();
$total += $item->getPrice();
$itemCount +=1;
}
echo "Total items this order: {$itemCount}\nYour total is: \${$total}";
Example. Now, to store that, you would just be storing the order array to the session and use it where needed. (note that the actual data comes from the database. You would store the keys from the database as well as the quantity.)