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

Did you know?Explore Trending and Topic pages for more stories like this.

$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

SELECT * FROM users WHERE Users are not in Blocked
How do I select all users from users table where there users_id is not stored in the block table

values not being entered into table
hi. I;ve created a form, so that when a user enters data into it, it gets added to a table in a data

Inter Company -- Resources Related Billing (Services Industry)
Hello,

My company has a scenario where:
Company A bills Company C for INTER (cross

$_POST
Hi, I have 2 seperate php files, and i want my $_POSt["fname"] To go into both of them, Fo

Need help making a blockquote and line items conditional
I have some code I bought a few years ago that allows my clients to update content on their site usi

Sending UDP Raw socket
I truly need help on this. I am trying to write a test program that simulate a network environment

Count number of records in all the tables with a querry URGENT PLEASE...
I downloaded ORACLE 9I DATA DUMP into my comp. There are number of tables. I need to find out the

ORA-01655: unable to extend cluster SYS.C_FILE#_BLOCK# by 128
Hi all,

Oracle 10g. Linux.

I'm facing the below error while trying to import a dumpfil

Pls help with PHP
Pls can anyone direct me on how to create a user account for a customer. For example i want know if

Trouble checking SESSION cookie
I am trying to use $_SESSION cookies to verify admin privileges .
I don't understand why this is

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