"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

Did you know?Explore Trending and Topic pages for more stories 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

Need some ideas as to how to go about sorting this array...
Here's how the array's are created..

Code: <?php
while ($x = readdir($dp)) {

HTML Email rec'd as Source Code
The code does create and send the email successfully. However, the message shows as html code and n

Buggy registration system
Hey, I just started scripting in PHP, and I ran into a few problems.
Code: <?php
includ

Transport data between itab and textfield on ALV event
Hallo,

I have a ALV Grid ( cl_gui_alv_grid ) and I also have hotspot click event with a h

How to read posted binary data from a mobile device and post it to a web server?
Here is the senario...

I have a mobile device (MD) that posts binary data to a Web Server (WS

Dump with added_funcion cl_salv_table
Hi there, I'm having some troubles adding a self defined function to an ALV in fullscreen. The thing

mysql_real_escape_string
Let me preface this that I am very much a PHP noob, but I have some SQL training (not necessarily My

Creating an invoice
Using fpdf I am trying to create an invoice to send to clients. The products are sold in pricing tie

RadioButtonList data selection
view plaincopy to clipboardprint?

Packet Design
Hi All,
Im new about network programming and I want to design a protocol but I have some question

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