Is there a way in PHP to include a constant in a string without concatenating?
define('MY_CONSTANT', 42);
echo "This is my constant: MY_CONSTANT";
Is there a way in PHP to include a constant in a string without concatenating?
define('MY_CONSTANT', 42);
echo "This is my constant: MY_CONSTANT";
You could do:
Yes it is (in some way ;) ):
This is probably not what you were aiming for, but I think, technically this is not concatenation but a substitution and from this assumption, it includes a constant in a string without concatenating.
If you really want to echo constant without concatenation here is solution:
note: in this example echo takes a number of parameters (look at the commas), so it isn't real concatenation
Echo behaves as a function, it takes more parameters, it is more efficient than concatenation, because it doesn't have to concatenate and then echo, it just echoes everything without the need of creating new String concatenated object :))
EDIT
Also if you consider concatenating strings, passings strings as parameters or writing whole strings with " , The , (comma version) is always fastest, next goes . (concatenation with ' single quotes) and the slowest string building method is using double quotes ", because expressions written this way have to be evaluated against declared variables and functions..
The easiest way is
Another way using
(s)printf
I believe this answers the OP's original question. The only thing is the globals index key seems to only work as lower case.
Output: