I get a this kind of a var_dumpwhen put a array inside to it
array(3)
[0]=> object(AppBundle\Entity\CartBookItem)#196 (5)
{["bookID":protected]=> int(1)
["quantity":protected]=> string(2) "10"
["name":protected]=> string(12) "Harry Potter"
["price":protected]=> int(700)
["category":protected]=> string(8) "Children" }
[1]=> object(AppBundle\Entity\CartBookItem)#184 (5)
{["bookID":protected]=> int(3)
["quantity":protected]=> string(1) "6"
["name":protected]=> string(14) "Harry Potter 2"
["price":protected]=> int(700)
["category":protected]=> string(8) "Children" }
[2]=> object(AppBundle\Entity\CartBookItem)#195 (5)
{ ["bookID":protected]=> int(2)
["quantity":protected]=> string(1) "1"
["name":protected]=> string(9) "the Beast"
["price":protected]=> int(544)
["category":protected]=> string(8) "Fiction" } }
[3]=> object(AppBundle\Entity\CartBookItem)#195 (5)
{ ["bookID":protected]=> int(2)
["quantity":protected]=> string(1) "7"
["name":protected]=> string(9) "the Beast 2"
["price":protected]=> int(544)
["category":protected]=> string(8) "Fiction" } }
So inside this array what Im trying to do is, to seperately get the quantity of each category. according to this example
Fiction quantity = 7
children quantity = 16
I tried to approach this way but it dint work out
foreach ($bookItems as $key => $bookItem) {
$q_counts = array_count_values(
array_column($bookItem, 'category')
);
}
Can somebody help me how to get the quantity counts separately?
Update getters from cartbookitem
public function getCategory()
{
return $this->category;
}
public function getQuantity()
{
return $this->quantity;
}