How to do math in PHP echo result -


the issue have need in following if:

<td>      <?php           if($result['job']['no_of_searches']<'5')          {               echo '<span class="badge bg-warning">100</span>';          }           if($result['job']['no_of_searches']>'5')          {               echo ‘problem-is-here’;          }      ?> </td> 

in problem-is-here field want display math result from:

<?php echo $result['job']['no_of_searches']; ?> / <?php echo $result['job']['total_autoaccepted']; ?> * 100  

but how can this?

it depends on type of $result[$x][$y].

  • if string, suggested code of developercoolio, has converted integer php function intval() before performing numerical operations on it. in case, however, string comparison <'5' unappropriate, because string '10' considered lower string '5', not behaviour expect.
  • if integer, code should rewritten follows

        if($result['job']['no_of_searches'] < 5)      {          echo '<span class="badge bg-warning">100</span>';      }      if($result['job']['no_of_searches'] > 5)      {         echo (int) (($result['job']['no_of_searches'] * 100) / $result['job']['total_autoaccepted']);      } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -