// defining function
function calPercentage($num, $total) {
$count1 = $num_amount / $num_total;
$count2 = $count1 * 100;
$count = number_format($count2, 0);
return $count;
}
// call function to calculate percentage
echo "Percentage of 100 in 1000 = ".calPercentage(100, 1000).'%<br/>';
echo "Percentage of 26 in 200 = ".calPercentage(26, 200).'%<br/>';
echo "Percentage of 30 in 400 = ".cal_percentage(30, 400).'%<br/>';
Output
Percentage of 100 in 1000 = 10%
Percentage of 26 in 200 = 13%
Percentage of 30 in 400 = 8%