"GROUP BY" in arrays


Posted on 16th Feb 2014 07:03 pm by admin

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

Code: $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:
Code: $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!

No comments posted yet

Your Answer:

Login to answer
67 Like 33 Dislike
Previous forums Next forums
Other forums

How to grab certain words ??
I am working with this API

Returns JSON.
curl http://letsbetrends.com/api/current_trends

Form Help
Here is the form:

Line number On/Off | Expand/Contract<? include("../include/sess

Login Control?!
I have a Web Site that uses the login control also I have set the destinationurl to the page I want

for loop without same $i digits?
Hi,

Can some guru please advise how can I accomplish this with a simple for loop ?

I

remove trailing slash from array
I have the following array which contains trailing slashes I need to remove. What is the best way to

Multiple includes losing variables
Hey all,

just starting out w php and ran into a problem pretty quickly. I'm
including seve

How to know if online site made with PHP
Hello,
I see some sites that does not display extensions at all , for example:

www.site.co

Printing issues with xMII 11.5
For some reason, we have one report (and only one) that is giving us fits when trying to print. The

Getting number of affected rows in SQLPLUS..
Hi everyone,
I have a shell script where i am invoking sqlplus, running a query and saving t

Creating XML with php
I need to creat an XML with php and have successfully produced a valid output.
The problem I hav

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash