πŸ“Š PHP
Q. What will be the output?
Code:
$a = [1,2,3];
foreach($a as $k => &$v) {}
$v = 10;
print_r($a);
  • (A) [1,2,3]
  • (B) [1,2,10]
  • (C) [10,10,10]
  • (D) Error
πŸ’¬ Discuss
βœ… Correct Answer: (B) [1,2,10]

Explanation: Reference persists after loop, modifying last element.

Explanation by: Roshan
Reference persists after loop, modifying last element.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
5
Total Visits
πŸ“½οΈ
8 d ago
Published
πŸŽ–οΈ
Roshan
Publisher
πŸ“ˆ
99%
Success Rate