Is it possible to do sum operations with sprintf
? In the example below, how do I decrease or add 1 in $idade
?
$idade = 10;
$str = '%d anos';
echo sprintf( $str , $idade );
Is it possible to do sum operations with sprintf
? In the example below, how do I decrease or add 1 in $idade
?
$idade = 10;
$str = '%d anos';
echo sprintf( $str , $idade );
Since sprintf
is a formatting function, it would not be incorrect to do:
<?php
$a = 1;
$b = 4;
$str = '%d anos menos %d = %d';
echo sprintf($str, $b, $a, $b-$a);
?>
[Edit]
function somar($a, $b){
return sprintf('%d anos menos %d = %d', $b, $a, $b-$a);
}
echo somar(1,10);