If $GLOBALS['filefolder'] = 13.pressrum
How come
$filefolder = '/'+$GLOBALS['filefolder'];
echo $filefolder
output 13
When
$filefolder = $GLOBALS['filefolder'];
echo $filfolder
outputs 13.pressrum
The operator +
is numeric / mathematical in PHP.
So '/'+$GLOBALS['filefolder'];
is equal to 0+13
in your case (php casts both to integer) which actually is 13.
To concatenate use .
$filefolder = '/' . $GLOBALS['filefolder'];
echo $filefolder
A +
adds two numbers as in 1+1. So if you use it to concatenate two strings, they get converted to integers internally and thus the result is 13. A dot (.
) concatenates two string. So you have to write $filefolder = '/'.$GLOBALS['filefolder'];
You probably confused it with JavaScript, where + is used to concatenate strings (and also for adding numbers, but that's another topic...).
The + operator in php is the sum. If you sum '/' + "13.pressrum", both will be casted to integer.
You should use . to concatenate strings.
+
is a mathematical operator, so PHP tries to find numbers in /
and 13.pressrum
it only finds the 13 so you get the result of 0 + 13
, which is 13
.
I guess what you wanted to do is concatenate the strings, try this:
$filefolder = '/'.$GLOBALS['filefolder'];
echo $filefolder
It should output /13.pressrum
.
+
to concatenate. It should be.
.