[Solved] If-else statement to count some variable


is this what you are looking for?

foreach([100, 500, 543, 1000, 5000, 51000, 500000] as $my_friends)
   echo '5 in '. getScoreOf($my_friends) . "<br>";

function getScoreOf($my_friends){
   $of = 5;
   $total = 5e5; //that's 500,000 ;)
   $step = 100; //minimum step, so output is not "4604" but "4600"
   $out_of = $total / $my_friends * $of;
   return $out_of > $step? round($out_of / $step) * $step: round($out_of);
}

run it in sandbox


edit: solution merged with original code

<?php
$of = 5;
$totalfriends = 100; 
$name = "Sam";
echo $of ." in ". getScoreOf($of, $totalfriends) ." people in city know ". $name;

function getScoreOf($of, $my_friends){
   $total = 5e6; //that's 5,000,000 ;)
   $step = 100; //minimum step, so output is not "4604" but "4600"
   $out_of = $total / $my_friends * $of;
   return $out_of > $step? round($out_of / $step) * $step: round($out_of);
}

6

solved If-else statement to count some variable