divide two numbers in php

To divide two numbers in PHP, you can use the division operator (/) as shown below:

main.php
$numerator = 10;
$denominator = 2;

$result = $numerator / $denominator;

echo $result; // Output: 5
101 chars
7 lines

In this example, the $numerator is divided by $denominator using the division operator (/) and the result is stored in $result. When we print $result, it will output 5 because 10 divided by 2 is 5.

You can also do division with variables directly in the echo statement as shown below:

main.php
$numerator = 10;
$denominator = 2;

echo $numerator / $denominator; // Output: 5
81 chars
5 lines

This will output the same result as the first example.

gistlibby LogSnag