PHP: Elegant way to avoid division by zero

后端 未结 7 467
小鲜肉
小鲜肉 2020-12-30 07:19

Much like this site, my current project has reputation and in the script that I\'m working on I need to calculate the ratio between two users\' reputations.

         


        
相关标签:
7条回答
  • 2020-12-30 08:06

    Something like this?

    if($defender->rep != 0){
        $attacker->ratio = $defender->rep / $attacker->rep;
    }
    
    0 讨论(0)
提交回复
热议问题