Concept
How do you concatenate strings in PHP?
ComputerScienceOne / String Functions
"PHP has a concatenation operator built into the language. To concatenate one or more strings together, you can use a simple period between them as the concatenation operator. Concatenation results in a new string.\n\n1 $firstName = \"Tom\";\n\n2 $lastName = \"Waits\";\n\n3\n\n4 $formattedName = $lastName . \", \" . $firstName;\n\n5 //formattedName now contains \"Waits, Tom\"\n\nConcatenation also works with other variable types.\n\n1 $x = 10;\n\n2 $y = 3.14;\n\n3\n\n4 $s = \"Hello, x is \" . $x . \" and y = \" . $y;\n\n5 //s contains \"Hello, x is 10 and y = 3.14\""
Related Ideas
- How can strings be concatenated in PHP?ComputerScienceOne · String Concatenation
- How does string concatenation work in Java?ComputerScienceOne · String Methods
- How can you create and reassign strings in PHP?ComputerScienceOne · Basics
- How are strings, statements, and code blocks written in PHP?ComputerScienceOne · Basic Syntax Rules
- How do you assign values to variables in PHP?ComputerScienceOne · Using Variables
- How can strings be used as indices in PHP arrays?ComputerScienceOne · Strings as Indices
- How does PHP support basic input and output?ComputerScienceOne · String Concatenation
- What is the order of precedence for PHP operators?ComputerScienceOne · If, If-Else, If-Else-If Statements