Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert a space between 2 echo

Tags:

php

echo

space

How do I add a space in the returned text between sample1 and sample2? Here is what I have so far:

if ($eventid!="") { 
   echo $get_event['sample1'], $get_event['sample2']; 
}
like image 924
Melany Chang Avatar asked Apr 30 '26 13:04

Melany Chang


2 Answers

It's really simple, just echo a space between the variables...

<?php if($eventid!=""){echo $get_event['sample1'] , ' ', $get_event['sample2']; }
like image 93
alex Avatar answered May 02 '26 05:05

alex


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

like image 39
Thiago Belem Avatar answered May 02 '26 06:05

Thiago Belem



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!