I have a form where a user enters 6 numbers. I've used a SimpleXML foreach loop to compare the entered numbers to the numbers in the xml file. I want to check if any 3 entered numbers match any 3 within an xml element, then display the date and match number associated with the element. I have it working if all 6 numbers match but trying to make it work if any 3 numbers match.
How do I use an array to get numbers and dates from the xml file and then extract and match against numbers entered on the form?
The code is what I have so far but doesn't use an array. It only compares 6 entered numbers against 6 in the xml file. I want to be able to use an array to collect the numbers and extract then compare.
XML (minified here)
<lottery>
<number>
<date>7.11.2015</date>
<num1>2</num1>
<num2>3</num2>
<num3>34</num3>
<num4>43</num4>
<num5>49</num5>
<num6>50</num6>
<match>10</match>
<jackpot>13156375</jackpot>
</number>
<number>
<date>08.11.2015</date>
<num1>11</num1>
<num2>13</num2>
<num3>18</num3>
<num4>25</num4>
<num5>29</num5>
<num6>47</num6>
<match>25</match>
<jackpot>8842605</jackpot>
</number>
PHP: This isnt using an array so only works to match 6 correct numbers
foreach($xml->children() as $record){
$n1 = $n1 || $record->num1 == $num1 || $record->num2 == $num1 || $record->num3 == $num1 || $record->num4 == $num1 || $record->num5 == $num1 || $record->num6 == $num1;
$n2 = $n2 || $record->num1 == $num2 || $record->num2 == $num2 || $record->num3 == $num2 || $record->num4 == $num2 || $record->num5 == $num2 || $record->num6 == $num2;
$n3 = $n3 || $record->num1 == $num3 || $record->num2 == $num3 || $record->num3 == $num3 || $record->num4 == $num3 || $record->num5 == $num3 || $record->num6 == $num3;
$n4 = $n4 || $record->num1 == $num4 || $record->num2 == $num4 || $record->num3 == $num4 || $record->num4 == $num4 || $record->num5 == $num4 || $record->num4 == $num1;
$n5 = $n5 || $record->num1 == $num5 || $record->num2 == $num5 || $record->num3 == $num5 || $record->num4 == $num5 || $record->num5 == $num5 || $record->num5 == $num1;
$n6 = $n6 || $record->num1 == $num6 || $record->num2 == $num6 || $record->num3 == $num6 || $record->num4 == $num6 || $record->num5 == $num6 || $record->num6 == $num6;
$jackpot = $record->jackpot;
$date = $record ->date;
}//end foreach
if ($n1 && $n2 && $n3 && $n4 && $n5 && $n6)
{
echo "<div class='col-md-6' id='date_won'>
<h3>DATE</h3>
<h3>".$record->date."</h3>
</div>
<div class='col-md-6' id='amount_won'>
<h3>AMOUNT</h3>
<h3>£".$record->jackpot."</h3>
</div>";
}
Im trying to create something like http://www.mrgamez.com/lottery-calculator/