$x = 123;
$y = 456;
$x = $y .= 789;
echo "$x<br>";
echo "$y<br>";
In my code here the result is
456789
456789
But this result isn't what i want, Since it is only $y
value
What i aim for is to echo
it separated like this
123789
456789
Since here i defined $x
& $y
then got an equal value, But instead of going $x .= 789
& $y .= 789
I just decided to merge them into one, But i got this only $y
value, How can i fix that?
With the following syntax:
$x = $y .= 789;
You're appending 789
to $y
, so you get 456789
. Then you're assigning this result into $x
- so at the end there are two 456789
values.
You cannot simplify this operation in one line - I'd highly suggest to do it in two lines, it's much more clear in understanding.
In your code first you are adding 789 in $y by &y .= 789. Then $y = 456789, After that you assign $y value in $x. So $x value replaced from 123 to 456789.
You have to do it separately.
<?php
$x = 123;
$y = 456;
$x .= 789; $y .= 789;
echo "$x<br>";
echo "$y<br>";
?>
You override the value of $x
. Assign them separately. Try this:
$x = 123;
$y = 456;
$x .= 789;
$y .= 789;
echo "$x<br>";
echo "$y<br>";