Bird
0
0

Which of the following is the correct way to declare a float variable with value 5.5 in PHP?

easy📝 Syntax Q3 of 15
PHP - Variables and Data Types
Which of the following is the correct way to declare a float variable with value 5.5 in PHP?
A$num = 5,5;
B$num = '5.5';
C$num = 5.5;
D$num = float(5.5);
Step-by-Step Solution
Solution:
  1. Step 1: Check PHP syntax for float assignment

    Assigning a float is done by directly assigning a decimal number without quotes.
  2. Step 2: Evaluate each option

    $num = 5.5; correctly assigns 5.5 as a float. $num = '5.5'; assigns a string, C is invalid syntax, D is not valid PHP syntax.
  3. Final Answer:

    $num = 5.5; -> Option C
  4. Quick Check:

    Correct float assignment = A [OK]
Quick Trick: Assign floats without quotes in PHP [OK]
Common Mistakes:
  • Using commas instead of dots
  • Assigning floats as strings
  • Using invalid float constructors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes