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

Do While statement
hi guys,

This may sound trivial but im new to php and as part of an assignmenti have to const

[Need Help] php timing issues
I don't know what is going wrong. I need some help with being able to set an image at 9:00am Colorad

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

Passing variables with pagination - iterating through unique id per link
Hi everyone,
I have seen a few topics like this one. Still cant find the specific thing, so I am

Calling strings from other php class
I have test1.php{
$string1;
$string2;
....
... //10 strings in this class <

Thread in PHP
Thread in PHP
Some basic use and basic code for thread in php
This is my question?

Comparing two dates
Hi Guys
I have two dates I want to compare. Below is my current implementation. The problem with

Generate PDF
Hi guys,

I would like to know if there is a way to generate pdf when clicking on a link. In f

Help, Base64 encoding url and decoding server side.
Hello everyone, i have a website with videos and games and also provide an embed code which people c

Pass sql into pl/sql and create RMAN duplicate script.
Hi,

I'm new to pl/sql and I'm trying to write a script that will generate some RMAN comma

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