Jump to content

"GROUP BY" in arrays


gdfhghjdfghgfhf

Recommended Posts

Well i'm looking to do something i usually could do easily using COUNT and GROUP BY if it was a sql query... But this time i'm working with an array...

 

so i have an array that looks like this

 

$array(
"dog",
"cat",
"dog",
"fish",
"horse",
"cat",
);

 

First i want to group together the duplicate entries. And then, i want to list the number of times the item was found in the array

 

with the above example, i would be expecting a result like this:

$array(
"dog (2 results)",
"cat (2 results)",
"fish (1 results)",
"horse (1 results)",
);

 

From what i have read on google i can group together the duplicate entry with array_unique() but i have no idea how i can list the number of times this item was found in the array

 

thanks for helping me!!

Link to comment
https://forums.phpfreaks.com/topic/186329-group-by-in-arrays/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.