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

i want run some web server under the ip sharer
hello i want run some web server under the ip sharer
my ip is floating ip but it doesnt matter

Basic Question Regarding PHP Includes
Hi

Just starting out with PHP.

Working on a site that uses some basic includes, these

passing an array of objects after submit
How do I do this? This is what I have tried and it is not working.

<form method="

PDO returns erroneous columns from within pdt
Hi All,

This is a truly weird behavior:
When using a simple pdo fetch, erroneous columns a

email CODING Problem
Email coding problem.

I need to send a section of the info to $tf and the same as a Cc to $em

Sending CC Info by email
I am a little bit less knowledgable in the security area as most developers and I know I have a lot

User registration and login
I don't know whether this is the correct forum, if not i apologise but am pretty desperate at the mo

updating a single value to multiple non consecutive rows
I need to update the same value to multiple non consecutive rows. I need to add an experation date t

What am I missing here? Help!
Hello all!. I can't seem to get this working right. Well - it renders right, but something is goin

Buggy registration system
Hey, I just started scripting in PHP, and I ran into a few problems.
Code: <?php
includ

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