"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

Help a newbee save my job !
Hey guys i am dying here i am new to php and would like for someone to help me with this problem

Save remote XML to local website folder
Hi, I hope you can help me out. I would like to be able to pull an XML file from another site and t

Losing 'page' data
I have this code that allows me to update my database. But after updating, I lose the $_GET['page']

Quick variable question
hey guys/gals,
im trying to write a php script and it works fine as i have it, but i need to set

breaking a text file into paragraphs based on strings
I have a text file of email addresses that is all squished together. It looks like this:

abc

Convert Binary String to Decimal
Trying to Get:
Decimal: 305419896

Out of:
Binary String: xV4

Remote Database Access
Hey guys!!

OK, i'm used to only working with databases from the CPANEL, accessing phpMyAdmin

Check Date/Time in PHP
What I need the code to check is that $reQuest is 24 hours in the past then return a time based on h

Ajax Issues - Update Panel / Timer. Intellisense doesn't know about them
Type 'System.Web.UI.ScriptManager' does not have a public property named 'UpdatePanel'. That is wha

remove innitial

and

tags
i am using tiny_mce as a text editor for my CMS.
buy now the problem is it add <p>

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