How to combine strings inside foreach into single string PHP

后端 未结 8 1393
傲寒
傲寒 2020-12-11 04:35

I have code like this

$word = \'foo\';
$char_buff = str_split($word);

foreach ($char_buff as $chars){
    echo var_dump($chars);
}

The out

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-11 05:16

    So, why do you split it just to make it a string again?

    $word='foo'
    $char_buff = str_split($word);
    
    $final = array();
    foreach ($char_buff as $chars){
        $final[] = $chars;
    }
    
    var_dump( implode('', $final) );
    

提交回复
热议问题