Best Practices: working with long, multiline strings in PHP?

前端 未结 10 2093
感情败类
感情败类 2020-11-27 09:59

Note: I\'m sorry if this is an extremely simple question but I\'m somewhat obsessive compulsive over the formatting of my code.

I have a class that has a function th

10条回答
  •  眼角桃花
    2020-11-27 10:35

    I like this method a little more for Javascript but it seems worth including here because it has not been mentioned yet.

    $var = "pizza";
    
    $text = implode(" ", [
      "I love me some",
      "really large",
      $var,
      "pies.",
    ]);
    
    // "I love me some really large pizza pies."
    

    For smaller things, I find it is often easier to work with array structures compared to concatenated strings.

    Related: implode vs concat performance

提交回复
热议问题