Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6196929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:43:45+00:00 2026-05-24T03:43:45+00:00

Edit – My question is not stricktly limited to preformance, I would also like

  • 0

Edit – My question is not stricktly limited to preformance, I would also like to know the pitfalls of each and if there is a condition where one should be used over the other.

Which is better to use to concat a string in PHP?

Option A: Use the . operator to concat the strings

$string1 = "hello ";
$string2 = $string1 . "world !";

Option B: Use double quotes

$string1 = "hello ";
$string2 = "$string1 world !";

I realize that both will in fact do the same thing, and in my personal development I prefer to use the . operator.
My question only arises because i’ve read that the . operator forces php to re-concatenate with each new string, so in the example:

$string1 = "hello ";
$string2 = "world";
$string3 = $string1.$string2." !";

would actually run slower than

$stirng1 = "hello";
$string2 = "world";
$string3 = "$string1 $string2 !";

Reference: PHP Language Operators > Strings

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:43:46+00:00Added an answer on May 24, 2026 at 3:43 am

    I think before you start worrying about it, you need to see if it is even worth thinking about. I did think about it, and wrote the following tiny script and ran it to see what the benchmarks were like.

    For each loop, I made 100,000 passes. Now I didn’t print my strings anywhere so if the PHP optimizer takes all of my work away because of that, then I apologize. However looking at these results, you are looking at a difference of about 0.00001 second for each.

    Before you optimize for anything other than readability, use a profiler and see where your hotspots are. If you run tens of millions of concatenations, then you may have an argument. But with 1000, you are still talking about a difference of 0.01 seconds. I’m sure you could save more than 0.01 seconds just by optimizing SQL queries and the like.

    My evidence is below….

    Here’s what I ran:

    <?php
    for($l = 0; $l < 5; $l++)
      {
        echo "Pass " .$l. ": \n";
        $starta = microtime(1);
        for( $i = 0; $i < 100000; $i++)
          {
        $a = md5(rand());
        $b = md5(rand());
        $c = "$a $b".' Hello';
          }
        $enda = microtime(1);
    
        $startb = microtime(1);
        for( $i = 0; $i < 100000; $i++)
          {
        $a = md5(rand());
        $b = md5(rand());
        $c = $a . ' ' . $b . ' Hello';
          }
        $endb = microtime(1);
    
    
        echo "\tFirst method: " . ($enda - $starta) . "\n";
        echo "\tSecond method: " . ($endb - $startb) . "\n";
      }
    

    Here are the results:

    Pass 0: 
        First method: 1.3060460090637
        Second method: 1.3552670478821
    Pass 1: 
        First method: 1.2648279666901
        Second method: 1.2579910755157
    Pass 2: 
        First method: 1.2534148693085
        Second method: 1.2467019557953
    Pass 3: 
        First method: 1.2516458034515
        Second method: 1.2479140758514
    Pass 4: 
        First method: 1.2541329860687
        Second method: 1.2839770317078
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: This question was written in 2008, which was like 3 internet ages ago.
edit #2: Question solved halfways. Look below As a follow-up question, does anyone know
Edit: I would like to model a 1 to 0:1 relationship between User and
Edit: I'm looking for solution for this question now also with other programming languages.
EDIT: This question was exceptionally dumb and made me look like a script kiddie,
Edit: From another question I provided an answer that has links to a lot
EDIT: Learned that Webmethods actually uses NLST, not LIST, if that matters Our business
EDIT: This question is more about language engineering than C++ itself. I used C++
Edit : Solved, there was a trigger with a loop on the table (read
Edit: The below question was answered by this . I have a new updated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.