Is there a better/shorter way in PHP of doing
$x = $x + 10;
i.e.
something like
$x .= 10; // (but this doesn't add together)
I am sure i've seen a shorter way tha开发者_JS百科n doing $x = $x + 10;
Have a look at: http://php.net/manual/language.operators.assignment.php (in the code examples and comments)
You can use:
$x += 10;
for example.
Not a PHP guy, but $x += 10;
maybe?
$x += 10;
However some people find this harder to read.
What you tried ($x.= 10
) works only for strings.
E.g.
$x = 'test';
$x.= 'ing...';
Like in many other languages:
$x += 10;
More information: Assignment Operators
$x+=10;
Is this what you're wanting?
$x += 10;
adds 10 to $x
or
$x += $x;
adds $x
to itself, but you could just do: $x *= 2;
You are looking for this:
$x += 10;
$x +=10; is equivalent to $x = $x +10;
http://www.tizag.com/phpT/operators.php
it's pretty simple. $x += 10; is same as $x = $x + 10;
精彩评论