To calculate PercentOf in PHP you can use the following snippet. It will calculate the percent of 2 given integers.

Sample PHP

Function PercentOf($int1, $int2) { 
	if ($int2 <= 0 || $int1 <=0){
		return 0;
	}
    $val1 = $int1 / $int2;  
    $retVal = $val1 * 100;  
    return $retVal;  
} 

If there is a 0 passed it will return 0.

2 thought on “How to calculate PercentOf in PHP”

Leave a Reply