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
Generate multilayered array from string.
ok so i have a string that looks like this:
Code: blog:edit_all,delete_all|users:edit_all,delete_
Posting to another Site?
I have software that people install.
When they install it, is there a way to make it post their d
Refining of search Criteria
Dear Friends
I need a help, I have a search page which of cars related, which has different s
How to make URL loads only on login
On my page, when a user login he's redirects to user_home.php. I made it also to open the chat scree
All possible combinations of String in PL/SQL
Hi All,
Could you please explain the logic of getting all possible combinations of String
INSERT for date range
Hi all
I have the following table
Code: [Select] `date` date
`day` int(2)
`
Searching keywords from array
Hello everyone, Im just wondering if someone could help me with another issue im having. Im still le
php title problem
Hi,
I am having a problem managing my page title with PHP.
Currently I have my <
Hardcopy printing is to wide
I want to make a hardcopy at runtime of my active form like this
Apple's revamped lineup arrives
I'm personally curious about the magic mouse.. a multi-touch concept sounds like it could be nea