Q:

How this is evaluated in PHP

While reading some questions on PHP. I read one question with it's answer as follows :
What will be the output of the code below and why?
$x = 5;
echo $x;
echo "<br />";
echo $x+++$x++;
echo "<br />";
echo $x;
echo "<br />";
echo $x---$x--;
echo "<br />";
echo $x;

Answer →
5
11
7
1
5

Here I am confused with $x+++ & $x--- & how its work & how exactly the expression $x+++$x++ evaluated. Can anybody please explain me about this. And also why just "echo $x+++" doesn't works & gives error.

A:

Okey lets see:
Now $x = 7
if we start with this line : echo $x---$x--; 
so whats happen???
($x--) - ($x--) =>  7 - 6 = 1

First $x-- does not effect on the first value but the value of $x will be one less, if we did $x-- in the second one then we get a less value of that variable and that is 6, so now the firs value is 7 and second value is 6, and because if the second value less, so the value of second portion will be less one which will effect on the next line: echo $x. So the last value is 5.
Analysis on Your Data:
$x = 5;
echo $x;         // 5, Nothing changed.
echo "<br />";   
echo $x+++$x++;  // 5 + 6 = 11, increment of $x two times.
echo "<br />";
echo $x;         // 7, cause last increment.
echo "<br />";
echo $x---$x--;  // 7 - 6 = 1, decrements two times.
echo "<br />";
echo $x;         // 5, cause last decrements. 

