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
17
Other forums
Custom list order
Hi there,
I have checked this tutorial and it's great till the point where I want to display
Must-Know Topics of PHP
Can you guys list the must-know topics of PHP. I am still a learner and I am trying to cover most of
need help with date function
i have following form for date
Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Help With editting and deleting form
Hallo !!
So look at this image :
http://img194.imageshack.us/img194/8272/snapshot5f.pn
Will this protect from mysql injection?
I do not want anything like DROP TABLE to work or any type of coding..
Heres my code.. is it
Please Help my PHP Dating Function.
Hi everyone!
Well here is my code that displays this:
It works wonderful.
Filtering Tables
Hello Thanks for any help any one can give Im very new to PHP..
I need to pull data for clien
Newb advice
Hi all,
I'm a flash front end designer and I've taken on a project that needs some back end p
post to self
Trying to get my form to submit to itself. However I am also trying to use an image for my submit bu
Checking BOM Authorization Group
Hai Friends,
I have developed a mulitilevel BOM display report. End users have been assig