PHP: Multiplication without multiplication operator.
Recently one of my friend asked me to write a function in PHP for multiplying two numbers without * or / operators. Also we should not use any loops. I got the following solution.
function mul($a,$b)
{
if($b==1){return $a;}
return $a+mul($a,$b-1);
}echo mul(5,6);
One more solution which i found is as follows. But is is using the division(/) operator.
function mul($a,$b)
{
return $a/(1/$b);
}echo mul(15,3);
Filed under: PHP | No Comments »










