Arif Hossin Arif Hossin - 2 months ago 11
PHP Question

How to show plus and minus sign when subtracting two variables:

How to show plus and minus sign when subtracting two variables:Following codes shows -1, that is fine but when the value is positive then it is not showing +sign.

$gf=5;
$ga=6;
$gd=$gf-$ga;
echo $gd;

Answer

Instead of echo, try this:

printf('%+d', $gd);

Reference: printf() string formatting