What is the best way to add two strings together?

前端 未结 12 530
自闭症患者
自闭症患者 2020-12-01 23:35

I read somewehere (I thought on codinghorror) that it is bad practice to add strings together as if they are numbers, since like numbers, strings cannot be changed. Thus, ad

12条回答
  •  孤街浪徒
    2020-12-01 23:56

    This is not a solution for 2 strings, but when you thinking of joining more strings best way like that:

    $tmp=srray();
    for(;;) $tmp[]='some string';
    $str=implode('',$tmp);
    

    It's faster to create array element and join them all at once, than join them hundred times.

提交回复
热议问题