Examveda
Examveda

What will be the output of the following PHP code?
<?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.

This Question Belongs to PHP >> Functions

Join The Discussion

Comments ( 1 )

  1. Anil Dadhich
    Anil Dadhich :
    5 years ago

    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.

Related Questions on Functions