dongxin8392 2015-08-11 13:25
浏览 76

PHP中的简单用户匹配逻辑[关闭]

I have an html page that has 1 textbox field for username and 5 checkboxes for that user to indicate which genres of music they like (ambient, rock, rap, jazz, pop). I duplicated the form fields twice more so that I can get the following data values:

Tom
Ambient
Rock
Rap

Sue
Rock
Rap
Jazz

Betty
Rock
Rap
Jazz

What is the best way to do a user matching algorithm in PHP? From the values about Sue and Betty would match 100% and Tom would match less than 100% with the other two.

Any suggestions?

below is the code

<p>Put in your name and pick the music genres you like:</p>
<form id="form1" name="form1" method="post" action="">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="12%"><label for="name"></label>
      <input type="text" name="name1" id="name1" vale="name1" placeholder="name 1"/></td>
      <td width="12%"><label for="name"></label>
        <input type="text" name="name2" id="name2" value="name2" placeholder="name 2"/></td>
      <td width="13%"><label for="name3"></label>
        <input type="text" name="name3" id="name3" value="name3" placeholder="name 3"/></td>
    </tr>
    <tr>
      <td><input type="checkbox" name="checkbox" id="checkbox" />
      <label for="checkbox">Ambient</label></td>
      <td><input type="checkbox" name="checkbox" id="checkbox" />
        <label for="checkbox">Ambient</label></td>
      <td><input type="checkbox" name="checkbox" id="checkbox" />
        <label for="checkbox">Ambient</label></td>
    </tr>
    <tr>
      <td><input type="checkbox" name="Rock" id="Rock" value="Rock"/>Rock</td>
      <td><input type="checkbox" name="Rock" id="Rock" value="Rock"/>
        Rock</td>
      <td><input type="checkbox" name="Rock" id="Rock" value="Rock"/>
        Rock</td>
    </tr>
    <tr>
      <td><input type="checkbox" name="Rap" id="Rap" value="Rap"/>Rap</td>
      <td><input type="checkbox" name="Rap" id="Rap" value="Rap"/>
        Rap</td>
      <td><input type="checkbox" name="Rap" id="Rap" value="Rap"/>
        Rap</td>
    </tr>
    <tr>
      <td><input type="checkbox" name="Jazz" id="JAzz" value="Jazz" />Jazz</td>
      <td><input type="checkbox" name="Jazz" id="JAzz" value="Jazz" />
        Jazz</td>
      <td><input type="checkbox" name="Jazz" id="JAzz" value="Jazz" />
        Jazz</td>
    </tr>
    <tr>
      <td><input type="checkbox" name="Pop" id="Pop" value="Pop" />Pop</td>
      <td><input type="checkbox" name="Pop" id="Pop" value="Pop" />
        Pop</td>
      <td><input type="checkbox" name="Pop" id="Pop" value="Pop" />
        Pop</td>
    </tr>
  </table>

  <br />
  <input type="submit" name="button" id="button" value="Submit" />
</form>
  • 写回答

3条回答

  • doufangpian5545 2015-08-11 13:36
    关注

    If you have the options as arrays you could do something with the array_diff function. i.e.

    <?php
    $tom = array("Ambient", "Rock", "Rap");
    $sue = array("Rock", "Rap", "Jazz");
    $betty = array("Rock", "Rap", "Jazz");
    
    //compare tom to sue
    $total = count($tom);
    $diff = count(array_diff($tom, $betty));
    $percent = 100 - ($diff / $total * 100);
    
    echo round($percent, 2)."% match between Tom and Sue";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)