To calculate 10% of a number in PHP, you simply multiply the number by 0.1. Here’s an example:
<?php
$number = 200; // Your number
$percentage = $number * 0.1; // 10% of the number
echo "10% of $number is $percentage";
?>
Result:
10% of 200 is 20
If you want to make the code more flexible to calculate any percentage, you can use the following function:
<?php
function calculatePercentage($number, $percent) {
return $number * ($percent / 100);
}
$number = 200;
$percent = 10;
$result = calculatePercentage($number, $percent);
echo "$percent% of $number is $result";
?>
This allows you to specify any percentage to calculate.