I need to append a value to two variables.
$a = "String A";
$b = "String B";
...
$a .= " more";
$b .= " more";
Is there a shorter way to get this work?
$a .= $b .= " more"; is not doing what I want.
Thanks in Advance, Matty
I need to append a value to two variables.
$a = "String A";
$b = "String B";
...
$a .= " more";
$b .= " more";
Is there a shorter way to get this work?
$a .= $b .= " more"; is not doing what I want.
Thanks in Advance, Matty
Not really.
$a .= $b .= " more";
Is equivalent to:
$b .= " more";
$a .= $b;
The best way is to write:
$a .= " more";
$b .= " more";
Or (if you have a lot of them) use array with some functions:
#1 - array_map approach
function addMore(&$vars) {
$var .= " more";
}
$array = [$a, $b];
$array = array_map('addMore',$array);
#2 - classic approach:
$array = array($a, $b);
foreach ($array_before as &$var) {
$var .= " more";
}