Insert a space between 2 echo
18,319
Solution 1
It's really simple, just echo
a space between the variables...
<?php if($eventid!=""){echo $get_event['sample1'] , ' ', $get_event['sample2']; }
Solution 2
Indentation always make things cleaner and easier:
if (!empty($eventid)) {
echo $get_event['sample1'] . ' ' . $get_event['sample2'];
}
On PHP, you need to use a dot (.) to concatenate strings... as you can see on the Strings Operators documentation:
http://php.net/manual/en/language.operators.string.php
Author by
Melany Chang
I work as marketing manager in a services company. My hobbies are computer, travelling and languages.
Updated on June 06, 2022Comments
-
Melany Chang almost 2 years
How do I add a space in the returned text between
sample1
andsample2
? Here is what I have so far:if ($eventid!="") { echo $get_event['sample1'], $get_event['sample2']; }
-
Melany Chang about 12 yearsif($eventid!=""){echo $get_event['sample1] , $get_event['sample2']; }
-
Mike Samuel about 12 yearsAre you missing a single quote after
'sample1
?
-
-
user3167101 about 12 years
echo
accepts multiple params as well, like the OP has used. -
Thiago Belem about 12 years@alex I didn't say it doesn't, both ways works.. Since he asked about concatenation, I said something about the dot and not multiple echo params, since you can't always "concatenate" strings with commas
-
user3167101 about 12 years@MelanyChang Simply change the string to
' , '
.