I was given this question as part of learning PHP.
What is the final value of $a?
$a .= "a";
$a .= "b";
$a .= "c";
I know it outputs "abc" and I understand that ".=" is a concatenation assignment, but I'm still a little unclear what is actually going on here. When I remove the periods I get "c", which makes sense that it would take the last item.
Thanks for any clarity.
$a .= "a"
...is shorthand for ...
$a = $a . "a"
At the beginning, $a is empty.
$a .= "a"
// now $a == "a"
$a .= "b"
// now $a == "a" . "b" == "ab"
$a .= "c"
// now $a == "ab" . "c" == "abc"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With