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 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建