Egrodo Egrodo - 1 year ago 37
PHP Question

Is there a function/way to automatically add spaces between output?

In PHP, I'm echoing a mix of strings and variables. I want to be able to automatically add a space between each piece, so I don't have to add a ' ' each time.


echo "This is my" . $string . ".";

This will output "This is mystring". is there some function I can wrap the echo in that will automatically place a space between? Thanks

Answer Source

A user-defined function can automatically add spaces and echo:

$four_five = 'four five';
echospace('one', 'two', 'three', $four_five, 'six');
// one two three four five six

function echospace () {
    echo join(' ', func_get_args());