"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

New to Arrays
Hi I am new to PHP (a week and a half now) and I am just beginning to read about arrays. I understan

Can anyone give me some link on .htaccess tutorial
i wish to have friendly url using .htaccess, but no idea yet about this

Hope that anyone cou

Creating Images from images in PHP
Okay well I am trying to make a 'dynamic' calender image with PHP.

I have images like this:

PHP Include not working
The website is http://www.grlistingservices.com

The code block is as follows:

<

Working with Dates, help.
Sooo to make a long story short, here's what im trying to accomplish.

I need to create a drop

Login Functionality Working Different on IE
This is an odd one, I have a site which has an admin section. The admin pages unsurprisingly require

Code error with Index.php
Error: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/runevid/public_

Can't get the unicode character
I'm trying to get some text from various parts of a file. I have converted the file to hex (bin2hex)

dropdown menu
Hello everbody,

I am php newbie.
I need to develop a program that once click the drop do

why isn't this PHP code working ???
it's suppose to find a name on the database.

<?php

$s = $_POST["lname&

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