How can I get the count of occurrence of array items while keeping the values as well. e.g.
$items = [{code: "2132", tile:"Mechanical Engineers"},
{code: "2134" title: "Chemical engineers"},
{code: :2132, title: "Mechanical Engineers}]
What I would like to achive is something like as follows:
$sortedItems = [{code: "2134" title: "Chemical engineers", count:1},
{code: "2132" title: "Chemical engineers", count:2}]
I'm using Larave and would like to get this either by using PHP array or even Laravel collection. Whichever works better.
Appreciate your help, as I am really stuck here and not sure how to proceed.