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
List/Menu Box
On an edit page when you want something to select what a user has previously selected from the datab
how do i display data on a page from mysql
1 - do i use this code at the top of each of my page i wish to only alow access if there as been a s
include problem
I have my root folder as:
Code: $root = $_SERVER["SITE_HTMLROOT"]; // the server root<
Undefined Index Notice In Internet Explorer Only
I am getting the following notice:
QuoteNotice: Undefined index: jrox in /home/ycsn/public_h
Mail Form receiving emails with no content
Hi, I hope someone here can help me.
I have a simple form in my website, it was working OK, after
Multi language - seo links
Im trying to figure out the best method to have a multi language website that will function with seo
Add User script "Could not execute query"
This should be an easy script but I can't get it to run. Can someone please help me?
<
php call servlet
I have done a php backup application .
So there is a form that user pick some files to zip and d
Logic question
im wondering what's the best method to do the above list:
it is for alliance @ MMORPG game
Estimations and Effort
HI Gurus,
Would like to know whether SAP have a provision for carrying out the Project es