I have 2 variables named $min and $sec.
If $min = 5 and $sec = 15 I want to print this "5m 15s", echo "$min m $sec s";
But that gives "5 m 15 s". How do I get rid of the blank space?
You can use braces to do this, same as many shells:
$min = 7;
$sec = 2;
echo "${min}m ${sec}s";
The output of that is:
7m 2s
The braces serve to delineate the variable name from the following text in situations where the "greedy" nature of variables would cause problems.
So, while $minm tries to give you the contents of the minm variable, ${min}m will give you the contents of the min variable followed by the literal m.
echo $min."m ".$sec."s"; is one way of doing it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With