Đoạn code sau đây cho ra kết quả gì?
$father = "mother";
$mother = "son";
echo $$father;
?>
Trả lời:
Đáp án đúng: A
Đoạn code PHP sử dụng khái niệm "variable variables".
1. `$father = "mother";`: Gán giá trị "mother" cho biến `$father`.
2. `$mother = "son";`: Gán giá trị "son" cho biến `$mother`.
3. `echo $$father;`: Đây là phần quan trọng. Vì `$father` có giá trị là "mother", `$$father` tương đương với `$mother`. Do đó, dòng này sẽ in ra giá trị của biến `$mother`, tức là "son".
Vậy kết quả của đoạn code là "son".