Jump to content

count matching results in two arrays


micah1701

Recommended Posts

So I have two arrays.
the first lists the winners of a series of games:

$winners = Array
(
[0] => New England
[1] => Buffalo
[2] => pittsburgh
[3] => St. Louis
)

and the other is a person's guess of who will win

$picks = Array
(
[0] => New England
[1] => NY Giants
[2] => Dallas
[3] => St. Louis
)

What is the best way to compare the arrays to see how many guesses in $picks match the results in $winners

if I had 1 pick, I could use in_array but I need to check each value in picks against the $winners array and determine a value for total matches. (ie, "2" in the example above)

thoughts on the best way to do it?
I always come up w/ hack jobs and make it 20 times more complicated then it needs to be.

[EDIT]

ok, well here's what I have:

[code]
  foreach($picks as $pick){
  if(in_array($pick,$winners)){
   $total = $total + 1;
   }
  }
  echo "you got $total correct";
[/code]

I guess thats pretty simple if no one has a better idea.
Link to comment
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.