I need to concatenate an indeterminate number of strings, and I would like a space in between two adjoining strings. Like so a b c d e f.
Also I do not want any leading or trailing spaces, what is the best way to do this in PHP?
You mean $str = implode(' ', array('a', 'b', 'c', 'd', 'e', 'f'));?
Simple way is:
$string="hello" . " " . "world";
                        function concatenate()
{
    $return = array();
    $numargs = func_num_args();
    $arg_list = func_get_args();
    for($i = 0; $i < $numargs; $i++)
    {
        if(empty($arg_list[$i])) continue;
        $return[] = trim($arg_list[$i]);
    }
    return implode(' ', $return);
}
echo concatenate("Mark ", " as ", " correct");
                        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