How do you connect data to string information in PHP?

Like in Java you’d have
String myString = "hello " + integerVar;
where integerVar is and integer variable; you’re using a + to connect the two. How do you do this in PHP?

2 Responses to “How do you connect data to string information in PHP?”

  • Matt:

    PHP is very flexible…

    // for scalars
    $myString = "hello $integerVar"; // interpolation
    $myString = "hello " . $integerVar; // concat

    // for array
    $myString = "hello {$integerVar[i][j]}"; // interpolation

  • Buddy Frank:

    You use a period (.) for concatenations in PHP.

    $sVar = "Hello".$cName."!";

Leave a Reply