array_count_values question?


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

ok i'm trying to create a top ten list from a database of listed favorite movies.

the following code yields me the correct order and number of votes for each movie


$compare = array_count_values ($anfo);

arsort($compare);

print_r($compare);



Array ( [] => 518 [pulp fiction] => 8 [fight club] => 8 [harry potter] => 7 [zoolander] => 7 [dirty

dancing] => 6 [ notebook] => 6 [mean girls] => 5 [juno] => 5 [300] => 5 [garden state] => 4 [a walk

to remember] => 4 [v for vendetta] => 4 )

I want to code things so that the above list is formated like a top ten list like so...

top movies
1 pulp fiction - 8 votes
2 fight club - 8 votes
3 harry potter - 8 votes
4 zoolander - 7 votes
5 dirty dancing - 6 votes
6 notebook - 6 votes
7 mean girls - 5 votes
8 300 - 5 votes
9 garden state - 4 votes
10 a walk to remember - 4 votes

what do i need to do to make that happen?

i tried

top 10 list

1. <?=$compare[1]?>

2. <?=$compare[2]?>

3. <?=$compare[3]?>




but that didn't work

update.... i just figured out the that i needed to use

$compare2 = array_keys($compare) ;

so that gives me the movie names, now i just need to figure out how to access the count values. any ideas?

No comments posted yet

Your Answer:

Login to answer
241 Like 17 Dislike
Previous forums Next forums
Other forums

trim function issues
Hi guys, total noob here...

So I've been tinkering around with a html and am using php to em

printing links
Hi every1

i am connecting to a table in sql and the looping through with a while ($ var = my

modifying query string with no page refresh
Hi everybody,
I've tried to get info about my problem all over the internet but i didn't find out

Merger of 6 sister companies under one flagship company after go live
Dear Experts,
I need one help regarding Merger of sister companies of same group. currently we

Function module "DPS_CHECK_TABLE_EXISTS" not found (after OSS 1422843 impl)
Dear All,

I implemented Note OSS 1422843.

When i execute the new report RSPO20

IS this code correct
The reason i ask is everything underneath it appears to be alink as well, tis blimmin annoying

Help with email validation please...
Hi,
Please could you help.
I have a register.php login page where users register, the detail

Spliting paragraph into sentences and attach in
Here is what I am trying to do

example: Para1[123.456.789!] 3 sentences
Para2

php redirecting
i wont open a new thread but i have a question about redirecting....
i wonder why my code doesnt

Disabling SAP menu
How do I disable SAP menu for all the users and just restrict them to User Menu in SAP ECC 6.0?

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