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
https://forums.phpfreaks.com/topic/69197-solved-match-only-three/
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;
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.