Jump to content

Recommended Posts

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<br>
1. <?=$compare[1]?><br>
2. <?=$compare[2]?><br>
3. <?=$compare[3]?><br>

 

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?

 

Link to comment
https://forums.phpfreaks.com/topic/190227-array_count_values-question/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.