Which is the best method to perform string concatenation in PHP?

前端 未结 4 1501
粉色の甜心
粉色の甜心 2021-01-19 03:26

In php we can append strings in many ways.

            Method 1
            ----------------------------
            $sql  = \"SELECT field1, \";
                    


        
相关标签:
4条回答
  • 2021-01-19 03:41

    creating the query itself doesn't take the smallest amount of memory or cpu(it does but in such small nr that it doesnt matter) from your computer but running it, is what you should be concerned about, make sure you have a proper index and so on

    0 讨论(0)
  • 2021-01-19 03:48

    As far as I'm concerned there is no 'best method'.
    Rule of thumb is choose one you prefer and stick to it and be consistent across the project.

    0 讨论(0)
  • 2021-01-19 03:51

    None is better. Just select one and stick to it, PHP_CodeSniffer can be used to automate a check on your code style.

    0 讨论(0)
  • 2021-01-19 04:06

    I vote for Method 3.

    The less concatenation operations, the better.

    Also, you should use single quotes as often as possible to avoid the PHP parser having to interpolate variables inside your strings.

    0 讨论(0)
提交回复
热议问题