duanfuxing2417 2016-08-10 14:46
浏览 39

使用数组存储数字和日期,然后匹配并从数组中提取它们?

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>&pound;".$record->jackpot."</h3>
    </div>";
}

Im trying to create something like http://www.mrgamez.com/lottery-calculator/

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求帮我调试一下freefem代码
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图