Reputation: 64276
I'm receiving string variable in php and need to add something to it.
I dump the variable and see:
var_dump($myvar);
string(length) " ... "
After that I write:
$myvar += '~';
And it's inserted into DB (This is wordpress plugin and I'm adding a text into post content).
As a result, I get '0' :( What could it be?
Upvotes: 1
Views: 107
Reputation: 168685
PHP uses a dot as the operator to concatenate strings, not a plus sign.
The plus sign adds numerically. This explains why you are getting the result of zero, because both of the strings you are adding are numerically equal to zero.
Both plus and dot can be combined with the equal sign in the way you are doing, so the corrected version of your line of code would look like this:
$myvar .= '~';
Hope that helps.
Upvotes: 3
Reputation: 808
If you want to add "~" behind your string you should do this:
REPLACE
$myvar += '~';
BY
$myvar .= '~';
Upvotes: 3
Reputation:
Try this code to add ~ symbol to your variable:
$myvar = $myvar."~"
Upvotes: 1