Jump to content

[SOLVED] Match Only Three?


papaface

Recommended Posts

Hello,

I have this code:

$numbers = array("04","13","18","21","30","46","(05)");

foreach	($data as $key => $value)
{
if	($data[$key][5] == $numbers[0] && $data[$key][6] == $numbers[1] && $data[$key][7] == $numbers[2] && $data[$key][8] == $numbers[3] && $data[$key][9] == $numbers[4] && $data[$key][10] == $numbers[5] && $data[$key][11] == $numbers[6] )//did they win the jackpot?
	{
	echo "You have Won!<br /><br />";
	}
else
	{
	echo "You did not win this time <br /><br />";
	}
}

The above code will check the $data[$key] array and match the values against the values in the $number array. That is fine.

However what if I wanted to see if only 3 values in the $numbers array matched the numbers in the $data[$key] array. How would I do that?

 

Any help would be appreciated as I can't work out how to do this

Link to comment
Share on other sites

A specific three, or just if any three but only three match?

Also, if it's a lottery they shouldn't have to get the numbers in order - they should just have to get all of them right, right?

Does this help:

<?php
$numbers = array("04","13","18","21","30","46");
$bonus = "(05)";
foreach	($data as $key => $value){
$numMatched = 0;
foreach($value AS $n){
	if(in_array($n, $numbers)){
		$numMatched++;
	}
}

print 'Matched '.$numMatched.' numbers<br>
        The bonus was: '.$bonus;
}
?>

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.