doudao1837 2013-04-12 11:09
浏览 46
已采纳

如何在php中比较三个数字时找到最高组合

There are three numbers in set A {3,4,7} and in set B {2,4,7}.

It is not possible to get the result true because the the first numbers in a and b are not same.

But I need to get the result as true by comparing other two number and leaving the first number.

How is it possible to do it in PHP?

  • 写回答

5条回答 默认 最新

  • dongyongyin5339 2013-04-12 12:01
    关注

    try this it will helps you.. it will display the 1 => for more number of combinations as same and 0 => for more of combination as different . in the below code the more number of combination as different so its returns 0.

    <?php
    $A = array(2,3,7,5,6);
    $B = array(4,3,7,8,9);
    
    $flagTrue = 0;
    $flagFalse = 0;
    for($i=0; $i < count($A); $i++)
    {
        if($A[$i] == $B[$i])
        {
            $flagTrue=$flagTrue+1;
        }
        else 
        {
            $flagFalse=$flagFalse+1;
        }
    }
    
    $var_is_greater_than_two = ($flagTrue >= $flagFalse) ? 1 : 0;
    echo $var_is_greater_than_two;
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应