Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q13 of 15
PHP - Functions
What will be the output of this PHP code?
function multiply(float $x, float $y) {
    return $x * $y;
}
echo multiply(3, 4.5);
A13.5
B12
CTypeError
D7.5
Step-by-Step Solution
Solution:
  1. Step 1: Understand parameter types and argument passing

    The function expects floats. PHP will convert integer 3 to float 3.0 automatically.
  2. Step 2: Calculate the multiplication

    3.0 * 4.5 = 13.5, so the function returns 13.5.
  3. Final Answer:

    13.5 -> Option A
  4. Quick Check:

    3 * 4.5 = 13.5 [OK]
Quick Trick: PHP auto-converts int to float if declared [OK]
Common Mistakes:
  • Expecting TypeError for int passed to float
  • Calculating wrong multiplication
  • Confusing output with integer result

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes