Best Way To Concatenate Strings In PHP With Spaces In Between

后端 未结 6 2116
抹茶落季
抹茶落季 2021-02-19 22:07

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

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-19 22:46

    $strings = array( " asd " , NULL, "", " dasd ", "Dasd  ", "", "", NULL );
    
    function isValid($v){
    return empty($v) || !$v ? false : true;
    }
    
    $concatenated = trim( implode( " ", array_map( "trim", array_filter( $strings, "isValid" ) ) ) );
    
    //"asd dasd Dasd"
    

提交回复
热议问题