我有一个用户输入6个数字的表单。我使用SimpleXML foreach循环将输入的数字与xml文件中的数字进行比较。我想检查是否有任何3个输入的数字与xml元素中的任何3匹配,然后显示与该元素关联的日期和匹配数。如果所有6个数字匹配但是如果任何3个数字匹配则尝试使其工作,我有它工作。
如何使用数组从xml文件中获取数字和日期,然后提取并匹配表单上输入的数字?
代码是我到目前为止但没有使用数组的代码。它仅将输入的6个数字与xml文件中的6个进行比较。我希望能够使用数组来收集数字并提取然后进行比较。
XML(这里缩小)
<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:这不是使用数组,因此只能匹配6个正确的数字
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>";
}
的内容