What will be the output of the following PHP code?
<?php
function calc($price, $tax="")
{
$total = $price + ($price * $tax);
echo "$total";
}
calc(42);
?>
<?php
function calc($price, $tax="")
{
$total = $price + ($price * $tax);
echo "$total";
}
calc(42);
?>
A. Error
B. 0
C. 42
D. 84
Answer: Option C
Solution(By Examveda Team)
You can designate certain arguments as optional by placing them at the end of the list and assigning them a default value of nothing.Join The Discussion
Comments ( 1 )
Related Questions on Functions
Which one of the following is the right way of defining a function in PHP?
A. function { function body }
B. data type functionName(parameters) { function body }
C. functionName(parameters) { function body }
D. function fumctionName(parameters) { function body }
A. Call By Value
B. Call By Reference
C. Default Argument Value
D. Type Hinting
Sir i think 42 is wrong answer because you pass $tax as string in function, so how we can multiply a number with a string.