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


$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?

241 Like 17 Dislike
Previous php-forum Next php-forum
Other php-forum

str_replace help
Hey there,

I'm a PHP newb, I'm having troubles with the str_replace function. I want to clean

Help With editting and deleting form
Hallo !!

So look at this image :

http://img194.imageshack.us/img194/8272/snapshot5f.pn

Switch letters in message (basic cryptology)...
I am trying to switch letters around in a message for an application on my site (see here). The prob

Preg_match with an array
is there an away to use preg_match with an array?

i want to check a string with an array to s

php and downloading
I want to use a php script to create two files. Then I want it to redirect (or whatever) to have tho

Just wondering what you think about my site
I am new to phpfreaks i just seen this form and thought it would be cool to see what other thought a

Convert Binary String to Decimal
Trying to Get:
Decimal: 305419896

Out of:
Binary String: xV4

Multiple Do / While Statements?
I'm still very new to PHP, and running in to a problem when trying to execute a do/while loop inside

Need to write a cookie with a url var
Not sure if its possible, but I need to write a cookie with a url.

So this would write 2232 a

Echoing If Function?
A script I am using has If statements in the comments form to basically tell the form what to do. Cu

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