Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q5 of 15
PHP - Arrays
What will be the output of this PHP code?
$arr = [10, 20, 30, 40];
$key = array_search(25, $arr);
var_dump($key);
Aint(2)
Bbool(false)
CNULL
Dint(25)
Step-by-Step Solution
Solution:
  1. Step 1: Check if 25 exists in array

    25 is not in the array [10, 20, 30, 40].
  2. Step 2: Understand array_search() return when not found

    array_search() returns false if value not found.
  3. Final Answer:

    bool(false) -> Option B
  4. Quick Check:

    Value missing returns false [OK]
Quick Trick: array_search() returns false if value missing [OK]
Common Mistakes:
  • Expecting NULL
  • Expecting index 2
  • Confusing value with key

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes