Reputation: 1908
Can I use.=
operator to append the same argument to 2 or more variables at the same time?
Like this (not working but example)
$a = "Hello";
$b = "Hi";
$a AND $b .= " World!";
// Now $a = "Hello World!" and $b = "Hi World!"
Upvotes: 3
Views: 215
Reputation: 519
No way to do this with concatenation assignment operator.
Upvotes: 1
Reputation: 816
You can use:
$items = array('Hello', 'Hi');
foreach ($items as &$item) $item .= ' World!';
var_dump($items);
Or:
$a = "Hello";
$b = "Hi";
foreach (array('a', 'b') as $key) $$key .= ' World';
var_dump($a);
var_dump($b);
Upvotes: 2