"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

Rounding a number queried from a database
I know that to display a rounded number you just do echo "round($number)";. But how would

check_changed_data - I can't get data from the called method event
I use check_changed_data to trigger my event method.

The method delivers er_changed_data.

CODE NOT WORKING
Code: [Select]<?php
//include shared codes

include '../lib/common.php';
include

Namespace Problem
I'm having problem with a section of code with a variable namespace.

This code works fine:

Update not working ... please help
Hi,

I am trying to update a row using an edit form by passing id of the row .. but it is not

Significance of BPM
Hi Experts,
I am a novice in BPM , I just want to know how BPM as permenant department is

confused between ' ' and " "
there is a php i set:
$begin_date_query = mysql_query( "SELECT SUBDATE(due_date, INTERVAL $d

strptime() equivalent for php4 ?!
Greetings!

this is my first post, thank you in advance for your replies.

Well, the ti

Procedure with variable number of columns
Hi, I have a procedure that looks like this:

PROCEDURE PROC(p_cursor OUT sys_refcurso

Access website from only 1 computer...?
One of my customers wants his website to only be accessed by people in which they bought the website

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