Reputation: 1721
How can I end a variable name in a string without using space or any other special character?
Example is there anything I can put between $num
and st
to output 1st
instead of 1 st
$num = 1;
echo "$num st";
Without using the dot opperator for concatination
Upvotes: 7
Views: 4944
Reputation: 943108
Wrap the name of the variable with braces.
$num = 1;
echo "${num}st";
Or use printf
syntax instead of simple interpolation:
$num = 1;
printf("%dst", $num);
Upvotes: 15