문제

I know you can assign to multiple variables in one call like so:

$varOne = $varTwo = "some value";

But is there a way append to multiple variables (strings) in one call?

Clearly this is incorrect syntax, but I was thinking something like this:

$varOne = "he's ";
$varTwo = "she's ";
$varOne, $varTwo .= "insane";

echo $varOne; // Outputs "he's insane"
echo $varTwo; // Outputs "she's insane"
도움이 되었습니까?

해결책

There is no way to concatenate 'in one call' like this in php outside making your own function and calling it. Appending operators work on only one variable.

다른 팁

Not possible, not really. At best, you could use variable variables like so:

 foreach (array('varOne', 'varTwo') as $var) {
     $$var .= 'insane';
 }

Variable variables are a maintenance headache though, and by maintenance headache, I mean a kitten gets killed each time you use the construct, so beware.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top