• PHP History
  • Install PHP
  • Hello World
  • PHP Constant
  • Predefined Constants
  • PHP Comments
  • Parameters and Arguments
  • Anonymous Functions
  • Variable Function
  • Arrow Functions
  • Variadic Functions
  • Named Arguments
  • Callable Vs Callback
  • Variable Scope
  • If Condition
  • If-else Block
  • Break Statement
  • Operator Precedence
  • PHP Arithmetic Operators
  • Assignment Operators
  • PHP Bitwise Operators
  • PHP Comparison Operators
  • PHP Increment and Decrement Operator
  • PHP Logical Operators

PHP String Operators

  • Array Operators
  • Conditional Operators
  • Ternary Operator
  • PHP Enumerable
  • PHP NOT Operator
  • PHP OR Operator
  • PHP Spaceship Operator
  • AND Operator
  • Exclusive OR
  • Spread Operator
  • Elvis Operator
  • Null Coalescing Operator
  • PHP Data Types
  • PHP Type Juggling
  • PHP Type Casting
  • PHP strict_types
  • Type Hinting
  • PHP Boolean Type
  • PHP Iterable
  • PHP Resource
  • Associative Arrays
  • Multidimensional Array
  • Programming
  • PHP Tutorial

In PHP, string operators, such as the concatenation operator (.) and its assignment variant (.=), are employed for manipulating and concatenating strings in PHP. This entails combining two or more strings. The concatenation assignment operator (.=) is particularly useful for appending the right operand to the left operand.

Concatenation Operator (.)

Concatenation assignment operator (.=), examples of concatenating strings in php, wrapping up.

Let’s explore these operators in more detail:

The concatenation operator (.) is utilized to combine two strings. Here’s an example:

You can concatenate more than two strings by chaining multiple concatenation operations.

Let’s take a look at another pattern of the concatenation operator, specifically the concatenation assignment operator.

The  .=  operator is a shorthand assignment operator that concatenates the right operand to the left operand and assigns the result to the left operand. This is particularly useful for building strings incrementally:

This is equivalent to  $greeting = $greeting . " World!"; .

Let’s see some examples

Here are some more advanced examples demonstrating the use of both the concatenation operator (.) and the concatenation assignment operator (.=) in PHP:

Concatenation Operator ( . ):

In this example, the  .  operator is used to concatenate multiple strings and variables into a single string.

Concatenation Assignment Operator ( .=) :

Here, the  .=  operator is used to append additional text to the existing string in the  $paragraph  variable. It is a convenient way to build up a string gradually.

Concatenation Within Iterations:

You can also use concatenation within iterations to build strings dynamically. Here’s an example using a loop to concatenate numbers from 1 to 5:

In this example, the  .=  operator is used within the  for  loop to concatenate the current number and a string to the existing  $result  string. The loop iterates from 1 to 5, building the final string. The  rtrim  function is then used to remove the trailing comma and space.

You can adapt this concept to various scenarios where you need to dynamically build strings within loops, such as constructing lists, sentences, or any other formatted output.

These examples showcase how you can use string concatenation operators in PHP to create more complex strings by combining variables, literals, iterations and other strings.

Let’s summarize it.

PHP provides powerful string operators that are essential for manipulating and concatenating strings. The primary concatenation operator (.) allows for the seamless combination of strings, while the concatenation assignment operator (.=) provides a convenient means of appending content to existing strings.

This versatility is demonstrated through various examples, including simple concatenation operations, the use of concatenation assignment for gradual string construction, and dynamic string building within iterations.

For more PHP tutorials, visit  here  or visit  PHP Manual .

Did you find this tutorial useful?

Your feedback helps us improve our tutorials.

  • Language Reference

Assignment Operators

The basic assignment operator is "=". Your first inclination might be to think of this as "equal to". Don't. It really means that the left operand gets set to the value of the expression on the right (that is, "gets set to").

The value of an assignment expression is the value assigned. That is, the value of " $a = 3 " is 3. This allows you to do some tricky things: <?php $a = ( $b = 4 ) + 5 ; // $a is equal to 9 now, and $b has been set to 4. ?>

In addition to the basic assignment operator, there are "combined operators" for all of the binary arithmetic , array union and string operators that allow you to use a value in an expression and then set its value to the result of that expression. For example: <?php $a = 3 ; $a += 5 ; // sets $a to 8, as if we had said: $a = $a + 5; $b = "Hello " ; $b .= "There!" ; // sets $b to "Hello There!", just like $b = $b . "There!"; ?>

Note that the assignment copies the original variable to the new one (assignment by value), so changes to one will not affect the other. This may also have relevance if you need to copy something like a large array inside a tight loop.

An exception to the usual assignment by value behaviour within PHP occurs with object s, which are assigned by reference. Objects may be explicitly copied via the clone keyword.

Assignment by Reference

Assignment by reference is also supported, using the " $var = &$othervar; " syntax. Assignment by reference means that both variables end up pointing at the same data, and nothing is copied anywhere.

Example #1 Assigning by reference

The new operator returns a reference automatically, as such assigning the result of new by reference is an error.

The above example will output:

More information on references and their potential uses can be found in the References Explained section of the manual.

Arithmetic Assignment Operators

Example Equivalent Operation
$a += $b $a = $a + $b Addition
$a -= $b $a = $a - $b Subtraction
$a *= $b $a = $a * $b Multiplication
$a /= $b $a = $a / $b Division
$a %= $b $a = $a % $b Modulus
$a **= $b $a = $a ** $b Exponentiation

Bitwise Assignment Operators

Example Equivalent Operation
$a &= $b $a = $a & $b Bitwise And
$a |= $b $a = $a | $b Bitwise Or
$a ^= $b $a = $a ^ $b Bitwise Xor
$a <<= $b $a = $a << $b Left Shift
$a >>= $b $a = $a >> $b Right Shift

Other Assignment Operators

Example Equivalent Operation
$a .= $b $a = $a . $b String Concatenation
$a ??= $b $a = $a ?? $b Null Coalesce
  • arithmetic operators
  • bitwise operators
  • null coalescing operator

Improve This Page

User contributed notes 4 notes.

To Top

Popular Articles

  • Echoing Content Directly (Aug 01, 2024)
  • Sgml Style (Aug 01, 2024)
  • Standard (Xml) Style (Aug 01, 2024)
  • Embedding Php In Web Pages (Aug 01, 2024)
  • Including Code (Aug 01, 2024)

String Concatenation Operator

Table of Contents

1. Introduction

2. understanding string concatenation, 3. the concatenation operator (.), 4. advanced string concatenation techniques, 5. concatenation assignment operator (.=), 6. performance considerations, 7. conclusion.

Imagine building a dynamic website where user input shapes the content displayed on each page. In PHP, a cornerstone of such interactivity involves the seamless integration of various strings, such as a user's name or choices, into web pages. This process, known as string concatenation, is crucial for creating personalised and engaging web experiences. This blog explores this fundamental concept, starting with its role in PHP, a pivotal language in server-side web development.

1.1 Specific focus on string concatenation as a fundamental operator

String concatenation in PHP allows developers to combine two or more strings into one. This operation is crucial for creating dynamic content where static HTML falls short. By mastering string concatenation, developers can craft messages, URLs, or SQL queries dynamically, enhancing the website's responsiveness and interactivity.

String concatenation, a fundamental skill for any PHP developer, involves combining two or more strings into a single string. This capability is vital for assembling text dynamically, such as generating personalized greetings or creating complex SQL queries on the fly.

2.1 Definition of string concatenation

String concatenation is the process of appending one string to the end of another. In PHP, this is achieved using the concatenation operator, which is denoted by a dot (.). This simple yet powerful feature enables the dynamic construction of strings from smaller fragments.

2.2 How PHP handles string concatenation

PHP provides a straightforward method for concatenating strings using the dot (.) operator. This operator takes two string operands and produces a new string that is the union of the two operands. The operation is not limited to just two strings and can be extended to concatenate multiple strings in a single expression.

2.3 Comparison with other programming languages

  • JavaScript uses the plus (+) operator for string concatenation, which can sometimes lead to confusion with numeric addition.
  • Python uses the plus (+) operator as well, but unlike JavaScript, Python is strongly typed, preventing the unintended mixing of strings and numbers.
  • Java also uses the plus (+) operator and provides additional capabilities like the StringBuilder class for more efficient concatenation in loops.

Understanding these differences is beneficial for developers who work across multiple languages, as it helps in adapting patterns and improving code portability.

In PHP, the concatenation operator, represented by a dot (.), is a critical tool for developers to merge strings. This operator facilitates the easy integration of variable content with static text, essential for dynamic web applications.

3.1 Syntax of the concatenation operator

The syntax for using the concatenation operator is straightforward:

This expression will combine $string1 and $string2 into a new string $concatenatedString.

3.2 Examples of basic string concatenation

Here are a few examples demonstrating basic string concatenation in PHP:

These examples show how strings can be combined to form complete sentences or messages, critical in customizing user experiences.

3.3 Common use cases in PHP programming

  • Dynamic HTML content: Developers can concatenate strings to create HTML tags dynamically. For example: $title = "My Page Title"; $html = "<h1>" . $title . "</h1>"; // Outputs: <h1>My Page Title</h1>
  • Email construction: Concatenation is useful for assembling email messages from various input fields. For example: $emailBody = "Dear " . $name . ",\nThank you for your inquiry...";
  • SQL queries: Securely concatenating strings to create SQL queries (though using parameterized queries is recommended to avoid SQL injection). For example: $query = "SELECT * FROM users WHERE name = '" . $userName . "'";

These use cases illustrate the versatility and power of the concatenation operator in PHP, enabling developers to write more dynamic, responsive, and flexible code.

Building on the basics of string concatenation, PHP developers can employ advanced techniques to manage more complex scenarios and optimise their code. These methods are crucial for handling large amounts of data, multi-part strings, or integrating variables dynamically.

PHP allows concatenating several strings in a single line using the concatenation operator repeatedly. This method is handy for constructing sentences or paragraphs with multiple dynamic parts. For example:

Concatenation becomes particularly powerful when combined with variables, enabling dynamic content generation. For instance:

This technique is frequently used in web applications to personalise user interactions based on session data or database queries.

Managing whitespace and special characters is crucial to ensure the readability and functionality of concatenated strings. PHP developers can use escaping techniques and whitespace management to maintain clarity and prevent errors, such as:

These methods ensure that the resulting strings are both user-friendly and machine-readable, essential for maintaining high-quality code standards.

The concatenation assignment operator .= in PHP simplifies the process of appending one string to another by modifying the original string directly. This operator is especially useful in scenarios where a string needs to be built incrementally, such as in loops or when constructing complex messages dynamically.

5.1 Explanation and syntax of the concatenation assignment operator

The .= operator combines the tasks of concatenation and assignment in one step. The syntax is straightforward:

This modifies $string by appending $additionalString directly to it, eliminating the need for a more verbose expression like $string = $string . $additionalString;.

5.2 Practical examples of using the concatenation assignment operator

Here are a few practical applications of the .= operator:

  • Building a list in HTML: $html = "<ul>"; foreach ($items as $item) { $html .= "<li>" . $item . "</li>"; } $html .= "</ul>"; This loop efficiently appends each item within a list tag to the $html string.
  • Generating a complex email body: $email = "Dear " . $name . ",\n"; $email .= "Thank you for your order. Here are the details:\n"; foreach ($orderDetails as $detail) { $email .= $detail . "\n"; } This example shows how to construct an email message by appending each order detail incrementally.

5.3 When to use .= over the basic concatenation operator

While both . and .= are useful, the assignment operator .= is particularly advantageous when the same string is being modified multiple times. It simplifies the code and can improve performance by reducing the number of operations. It is ideal for scenarios involving loops or conditional concatenations where incremental string building is required.

Efficiently managing string concatenation in PHP is pivotal for optimizing the performance of web applications. This aspect becomes particularly significant in scenarios dealing with large volumes of data or high-frequency operations. Here, we explore best practices and highlight common pitfalls to avoid.

6.1 Efficiency of string concatenation in PHP

String concatenation in PHP is generally efficient, but the performance can degrade if not handled properly, especially in loops or large-scale data processing. The misuse of concatenation, particularly in a loop, can lead to increased memory usage and slower execution times. It's crucial to understand the internals: PHP strings are immutable, meaning each concatenation operation might result in creating a new string in memory, depending on the context and PHP version.

6.2 Best practices for optimizing string concatenation

To enhance performance when using string concatenation, consider the following tips:

  • Minimize operations inside loops: Avoid using concatenation directly within loop conditions that execute numerous times. Instead, consider buffering outputs or using prebuilt functions like implode() for arrays.
  • Use the concatenation assignment operator wisely: For building strings incrementally, .= can be more efficient than repeatedly using . because it reduces the overhead of creating new strings.
  • Preallocate string length if possible: When dealing with very large strings, preallocating the string's total length can sometimes improve performance, although this technique is more relevant in other programming languages with different string management.

6.3 Potential pitfalls and how to avoid them

Being aware of common pitfalls can greatly improve string handling efficiency:

  • Excessive memory use: Concatenating very large strings or numerous small strings repeatedly can exhaust memory resources. Monitor memory usage and refactor code using more memory-efficient methods when necessary.
  • Loss of readability: Overuse of concatenation, especially with complex expressions, can make code hard to read and maintain. Strive for clarity by breaking down complex concatenations or using formatted strings when appropriate.
  • Security issues: When concatenating strings to create SQL queries or HTML content, ensure to escape or sanitize inputs to prevent security vulnerabilities like SQL injection or cross-site scripting (XSS).

By adhering to these best practices and being mindful of potential pitfalls, developers can maintain high-performance standards in their PHP applications while ensuring the code remains secure and efficient.

String concatenation is an indispensable tool in PHP, serving as the backbone for creating dynamic and interactive web content. Throughout this discussion, we've explored the mechanics of the concatenation operator and its extended functionality through the concatenation assignment operator, alongside practical examples and performance considerations.

7.1 Recap of key points about the string concatenation operator in PHP

We've covered the essential aspects of string concatenation in PHP, emphasizing:

  • The basic usage and syntax of the concatenation operator . and the concatenation assignment operator .=.
  • Practical examples showcasing how these operators can be utilized in real-world applications to enhance functionality and user experience.
  • Advanced techniques and best practices for optimizing string concatenation to maintain efficient, readable, and secure code.

7.2 Final thoughts on the importance of understanding operators in PHP

Mastering the use of string concatenation and other operators is crucial for any PHP developer aiming to build robust, dynamic, and secure web applications. These operators not only provide the mechanism to manipulate data effectively but also play a significant role in optimizing performance and ensuring application security.

7.3 Encouragement to practice and experiment with examples provided

To truly grasp the power and versatility of string concatenation in PHP, it is highly recommended to practice with the examples provided and experiment with creating your own use cases. Practical application of these concepts will reinforce learning and improve coding proficiency, paving the way for more innovative and effective web development.

  • PHP Tutorial
  • PHP Exercises
  • PHP Calendar
  • PHP Filesystem
  • PHP Programs
  • PHP Array Programs
  • PHP String Programs
  • PHP Interview Questions
  • PHP IntlChar
  • PHP Image Processing
  • PHP Formatter
  • Web Technology

How to Concatenate Strings in PHP ?

In PHP , strings can be concatenated using the( . operato r). Simply place the ” . " between the strings you wish to concatenate, and PHP will merge them into a single string.

Using (.operator)

In PHP, the dot (.) operator is used for string concatenation. By placing the dot between strings and variables, they can be combined into a single string. This method provides a concise and efficient way to merge string elements.

Alternatively, you can also use the .= operator to append one string to another, like so:

Using sprintf() Function

PHP’s sprintf() function allows for formatted string construction by replacing placeholders with corresponding values. It offers a structured approach to string concatenation, particularly useful for complex string compositions.

Similar Reads

  • Web Technologies
  • WebTech-FAQs

Please Login to comment...

  • How to Watch NFL on NFL+ in 2024: A Complete Guide
  • Best Smartwatches in 2024: Top Picks for Every Need
  • Top Budgeting Apps in 2024
  • 10 Best Parental Control App in 2024
  • GeeksforGeeks Practice - Leading Online Coding Platform

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

  • How to Concatenate Strings in PHP

Use the Concatenation Operator to Concatenation Strings in PHP

Use the concatenation assignment operator to concatenate strings in php, use the sprintf() function to concatenate strings in php.

How to Concatenate Strings in PHP

This article will introduce different methods to perform string concatenation in PHP.

The process of joining two strings together is called the concatenation process. In PHP, we can achieve this by using the concatenation operator. The concatenation operator is . . The correct syntax to use this operator is as follows.

The details of these variables are as follows.

Variables Description
It is the string in which we will store the concatenated strings.
It is the string that we want to concatenate with the other string.
It is the string that we want to concatenate with the first string.

The program below shows how we can use the concatenation operator to combine two strings.

Likewise, we can use this operator to combine multiple strings.

In PHP, we can also use the concatenation assignment operator to concatenate strings. The concatenation assignment operator is .= . The difference between .= and . is that the concatenation assignment operator .= appends the string on the right side. The correct syntax to use this operator is as follows.

Variables Description
It is the string with which we want to append a new string on the right side.
It is the string that we want to concatenate with the first string.

The program below shows how we can use the concatenation assignment operator to combine two strings.

In PHP, we can also use the sprintf() function to concatenate strings. This function gives several formatting patterns to format strings. We can use this formatting to combine two strings. The correct syntax to use this function is as follows.

The function sprintf() accepts N+1 parameters. The detail of its parameters is as follows.

Parameters Description
mandatory The format will be applied to the given string or strings.
, , mandatory It is the string we want to format. At least one string is mandatory.

The function returns the formatted string. We will use the format %s %s to combine two strings. The program that combines two strings is as follows:

Related Article - PHP String

  • How to Remove All Spaces Out of a String in PHP
  • How to Convert DateTime to String in PHP
  • How to Convert String to Date and Date-Time in PHP
  • How to Convert an Integer Into a String in PHP
  • How to Convert an Array to a String in PHP
  • How to Convert a String to a Number in PHP

Concatenate Strings in PHP

Php examples tutorial index.

Concatenating strings is a crucial concept in PHP that enables developers to merge two or more strings to create a single string. Understanding how to concatenate strings efficiently is vital in generating dynamic content, creating queries, and managing data output. In this tutorial, you will learn how to concatenate strings in PHP.

Understanding String Concatenation in PHP

String concatenation refers to joining two or more strings to create a new string. It is a typical and helpful operation in PHP, allowing developers to create customized and dynamic strings by combining different sources. The dot ( . ) operator performs this operation in PHP by joining the strings and creating a new string. This feature is simple and efficient and is commonly used in PHP scripting.

Basic Concatenation with the Dot Operator

The easiest and most common way to concatenate strings in PHP is to use the dot ( . ) operator. The dot operator takes two operands (the strings to be concatenated) and returns a new string as the result of concatenating them.

In the above example, we combine two variables ( $firstName and $lastName ) with a space between them to form a full name.

Concatenation with Assignment Operator

PHP makes string manipulation easier with the concatenation assignment operator ( .= ). This operator appends the right-side argument to the left-side argument, making it simple to expand an existing string.

The above method simplifies how to efficiently append text to an existing string variable, enhancing its content without redundancy.

Concatenating Multiple Variables and Strings

You can concatenate multiple variables and strings using multiple dot operators in a single statement. It is beneficial when you need to create a sentence or message from different data sources:

Dynamic Content Creation

String concatenation helps generate dynamic content and allows tailored user experiences based on specific inputs or conditions.

The above example illustrates how to create a personalized greeting message using concatenation dynamically.

In this tutorial, you have learned about the process of string concatenation in PHP, how to use the dot and assignment operators to join strings together, and some examples of string concatenation in PHP for different purposes. String concatenation is a crucial aspect of managing dynamic content and data output. Applying the best practices and techniques outlined in this tutorial, you can efficiently use string concatenation in your PHP projects.

Home » PHP Tutorial » PHP Assignment Operators

PHP Assignment Operators

Summary : in this tutorial, you will learn about the most commonly used PHP assignment operators.

Introduction to the PHP assignment operator

PHP uses the = to represent the assignment operator. The following shows the syntax of the assignment operator:

On the left side of the assignment operator ( = ) is a variable to which you want to assign a value. And on the right side of the assignment operator ( = ) is a value or an expression.

When evaluating the assignment operator ( = ), PHP evaluates the expression on the right side first and assigns the result to the variable on the left side. For example:

In this example, we assigned 10 to $x, 20 to $y, and the sum of $x and $y to $total.

The assignment expression returns a value assigned, which is the result of the expression in this case:

It means that you can use multiple assignment operators in a single statement like this:

In this case, PHP evaluates the right-most expression first:

The variable $y is 20 .

The assignment expression $y = 20 returns 20 so PHP assigns 20 to $x . After the assignments, both $x and $y equal 20.

Arithmetic assignment operators

Sometimes, you want to increase a variable by a specific value. For example:

How it works.

  • First, $counter is set to 1 .
  • Then, increase the $counter by 1 and assign the result to the $counter .

After the assignments, the value of $counter is 2 .

PHP provides the arithmetic assignment operator += that can do the same but with a shorter code. For example:

The expression $counter += 1 is equivalent to the expression $counter = $counter + 1 .

Besides the += operator, PHP provides other arithmetic assignment operators. The following table illustrates all the arithmetic assignment operators:

OperatorExampleEquivalentOperation
+=$x += $y$x = $x + $yAddition
-=$x -= $y$x = $x – $ySubtraction
*=$x *= $y$x = $x * $yMultiplication
/=$x /= $y$x = $x / $yDivision
%=$x %= $y$x = $x % $yModulus
**=$z **= $y$x = $x ** $yExponentiation

Concatenation assignment operator

PHP uses the concatenation operator (.) to concatenate two strings. For example:

By using the concatenation assignment operator you can concatenate two strings and assigns the result string to a variable. For example:

  • Use PHP assignment operator ( = ) to assign a value to a variable. The assignment expression returns the value assigned.
  • Use arithmetic assignment operators to carry arithmetic operations and assign at the same time.
  • Use concatenation assignment operator ( .= )to concatenate strings and assign the result to a variable in a single statement.

PHP Tutorial

  • PHP Tutorial
  • PHP - Introduction
  • PHP - Installation
  • PHP - History
  • PHP - Features
  • PHP - Syntax
  • PHP - Hello World
  • PHP - Comments
  • PHP - Variables
  • PHP - Echo/Print
  • PHP - var_dump
  • PHP - $ and $$ Variables
  • PHP - Constants
  • PHP - Magic Constants
  • PHP - Data Types
  • PHP - Type Casting
  • PHP - Type Juggling
  • PHP - Strings
  • PHP - Boolean
  • PHP - Integers
  • PHP - Files & I/O
  • PHP - Maths Functions
  • PHP - Heredoc & Nowdoc
  • PHP - Compound Types
  • PHP - File Include
  • PHP - Date & Time
  • PHP - Scalar Type Declarations
  • PHP - Return Type Declarations
  • PHP Operators
  • PHP - Operators
  • PHP - Arithmatic Operators
  • PHP - Comparison Operators
  • PHP - Logical Operators
  • PHP - Assignment Operators
  • PHP - String Operators
  • PHP - Array Operators
  • PHP - Conditional Operators
  • PHP - Spread Operator
  • PHP - Null Coalescing Operator
  • PHP - Spaceship Operator
  • PHP Control Statements
  • PHP - Decision Making
  • PHP - If…Else Statement
  • PHP - Switch Statement
  • PHP - Loop Types
  • PHP - For Loop
  • PHP - Foreach Loop
  • PHP - While Loop
  • PHP - Do…While Loop
  • PHP - Break Statement
  • PHP - Continue Statement
  • PHP - Arrays
  • PHP - Indexed Array
  • PHP - Associative Array
  • PHP - Multidimensional Array
  • PHP - Array Functions
  • PHP - Constant Arrays
  • PHP Functions
  • PHP - Functions
  • PHP - Function Parameters
  • PHP - Call by value
  • PHP - Call by Reference
  • PHP - Default Arguments
  • PHP - Named Arguments
  • PHP - Variable Arguments
  • PHP - Returning Values
  • PHP - Passing Functions
  • PHP - Recursive Functions
  • PHP - Type Hints
  • PHP - Variable Scope
  • PHP - Strict Typing
  • PHP - Anonymous Functions
  • PHP - Arrow Functions
  • PHP - Variable Functions
  • PHP - Local Variables
  • PHP - Global Variables
  • PHP Superglobals
  • PHP - Superglobals
  • PHP - $GLOBALS
  • PHP - $_SERVER
  • PHP - $_REQUEST
  • PHP - $_POST
  • PHP - $_GET
  • PHP - $_FILES
  • PHP - $_ENV
  • PHP - $_COOKIE
  • PHP - $_SESSION
  • PHP File Handling
  • PHP - File Handling
  • PHP - Open File
  • PHP - Read File
  • PHP - Write File
  • PHP - File Existence
  • PHP - Download File
  • PHP - Copy File
  • PHP - Append File
  • PHP - Delete File
  • PHP - Handle CSV File
  • PHP - File Permissions
  • PHP - Create Directory
  • PHP - Listing Files
  • Object Oriented PHP
  • PHP - Object Oriented Programming
  • PHP - Classes and Objects
  • PHP - Constructor and Destructor
  • PHP - Access Modifiers
  • PHP - Inheritance
  • PHP - Class Constants
  • PHP - Abstract Classes
  • PHP - Interfaces
  • PHP - Traits
  • PHP - Static Methods
  • PHP - Static Properties
  • PHP - Namespaces
  • PHP - Object Iteration
  • PHP - Encapsulation
  • PHP - Final Keyword
  • PHP - Overloading
  • PHP - Cloning Objects
  • PHP - Anonymous Classes
  • PHP Web Development
  • PHP - Web Concepts
  • PHP - Form Handling
  • PHP - Form Validation
  • PHP - Form Email/URL
  • PHP - Complete Form
  • PHP - File Inclusion
  • PHP - GET & POST
  • PHP - File Uploading
  • PHP - Cookies
  • PHP - Sessions
  • PHP - Session Options
  • PHP - Sending Emails
  • PHP - Sanitize Input
  • PHP - Post-Redirect-Get (PRG)
  • PHP - Flash Messages
  • PHP - AJAX Introduction
  • PHP - AJAX Search
  • PHP - AJAX XML Parser
  • PHP - AJAX Auto Complete Search
  • PHP - AJAX RSS Feed Example
  • PHP - XML Introduction
  • PHP - Simple XML Parser
  • PHP - SAX Parser Example
  • PHP - DOM Parser Example
  • PHP Login Example
  • PHP - Login Example
  • PHP - Facebook and Paypal Integration
  • PHP - Facebook Login
  • PHP - Paypal Integration
  • PHP - MySQL Login
  • PHP Advanced
  • PHP - MySQL
  • PHP.INI File Configuration
  • PHP - Array Destructuring
  • PHP - Coding Standard
  • PHP - Regular Expression
  • PHP - Error Handling
  • PHP - Try…Catch
  • PHP - Bugs Debugging
  • PHP - For C Developers
  • PHP - For PERL Developers
  • PHP - Frameworks
  • PHP - Core PHP vs Frame Works
  • PHP - Design Patterns
  • PHP - Filters
  • PHP - Callbacks
  • PHP - Exceptions
  • PHP - Special Types
  • PHP - Hashing
  • PHP - Encryption
  • PHP - is_null() Function
  • PHP - System Calls
  • PHP - HTTP Authentication
  • PHP - Swapping Variables
  • PHP - Closure::call()
  • PHP - Filtered unserialize()
  • PHP - IntlChar
  • PHP - CSPRNG
  • PHP - Expectations
  • PHP - Use Statement
  • PHP - Integer Division
  • PHP - Deprecated Features
  • PHP - Removed Extensions & SAPIs
  • PHP - FastCGI Process
  • PHP - PDO Extension
  • PHP - Built-In Functions
  • PHP Useful Resources
  • PHP - Questions & Answers
  • PHP - Quick Guide
  • PHP - Useful Resources
  • PHP - Discussion
  • Selected Reading
  • UPSC IAS Exams Notes
  • Developer's Best Practices
  • Questions and Answers
  • Effective Resume Writing
  • HR Interview Questions
  • Computer Glossary

PHP – String Operators

There are two operators in PHP for working with string data types: concatenation operator (".") and the concatenation assignment operator (".="). Read this chapter to learn how these operators work in PHP.

Concatenation Operator in PHP

The dot operator (".") is PHP's concatenation operator. It joins two string operands (characters of right hand string appended to left hand string) and returns a new string.

The following example shows how you can use the concatenation operator in PHP −

It will produce the following output −

Concatenation Assignment Operator in PHP

PHP also has the ".=" operator which can be termed as the concatenation assignment operator. It updates the string on its left by appending the characters of right hand operand.

The following example uses the concatenation assignment operator. Two string operands are concatenated returning the updated contents of string on the left side −

String Operators in PHP : Tutorial

Concatenation Operator

Concatenation assignment operator (.=).

Primary links

  • HTML Color Chart
  • Knowledge Base
  • Devguru Resume
  • Testimonials
  • Privacy Policy

Font-size: A A A

PHP » Operators » .=

Concatenation assignment operator.

Concatenates the left operand and the right operand.

Explanation:

A variable is changed with an assignment operator.

concatenation assignment operator php

© Copyright 1999-2018 by Infinite Software Solutions, Inc. All rights reserved.

Trademark Information | Privacy Policy

Event Management Software and Association Management Software

PHP Tutorial

Php advanced, mysql database, php examples, php reference, php operators.

Operators are used to perform operations on variables and values.

PHP divides the operators in the following groups:

  • Arithmetic operators
  • Assignment operators
  • Comparison operators
  • Increment/Decrement operators
  • Logical operators
  • String operators
  • Array operators
  • Conditional assignment operators

PHP Arithmetic Operators

The PHP arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication etc.

Operator Name Example Result Try it
+ Addition $x + $y Sum of $x and $y
- Subtraction $x - $y Difference of $x and $y
* Multiplication $x * $y Product of $x and $y
/ Division $x / $y Quotient of $x and $y
% Modulus $x % $y Remainder of $x divided by $y
** Exponentiation $x ** $y Result of raising $x to the $y'th power

PHP Assignment Operators

The PHP assignment operators are used with numeric values to write a value to a variable.

The basic assignment operator in PHP is "=". It means that the left operand gets set to the value of the assignment expression on the right.

Assignment Same as... Description Try it
x = y x = y The left operand gets set to the value of the expression on the right
x += y x = x + y Addition
x -= y x = x - y Subtraction
x *= y x = x * y Multiplication
x /= y x = x / y Division
x %= y x = x % y Modulus

Advertisement

PHP Comparison Operators

The PHP comparison operators are used to compare two values (number or string):

Operator Name Example Result Try it
== Equal $x == $y Returns true if $x is equal to $y
=== Identical $x === $y Returns true if $x is equal to $y, and they are of the same type
!= Not equal $x != $y Returns true if $x is not equal to $y
<> Not equal $x <> $y Returns true if $x is not equal to $y
!== Not identical $x !== $y Returns true if $x is not equal to $y, or they are not of the same type
> Greater than $x > $y Returns true if $x is greater than $y
< Less than $x < $y Returns true if $x is less than $y
>= Greater than or equal to $x >= $y Returns true if $x is greater than or equal to $y
<= Less than or equal to $x <= $y Returns true if $x is less than or equal to $y
<=> Spaceship $x <=> $y Returns an integer less than, equal to, or greater than zero, depending on if $x is less than, equal to, or greater than $y. Introduced in PHP 7.

PHP Increment / Decrement Operators

The PHP increment operators are used to increment a variable's value.

The PHP decrement operators are used to decrement a variable's value.

Operator Same as... Description Try it
++$x Pre-increment Increments $x by one, then returns $x
$x++ Post-increment Returns $x, then increments $x by one
--$x Pre-decrement Decrements $x by one, then returns $x
$x-- Post-decrement Returns $x, then decrements $x by one

PHP Logical Operators

The PHP logical operators are used to combine conditional statements.

Operator Name Example Result Try it
and And $x and $y True if both $x and $y are true
or Or $x or $y True if either $x or $y is true
xor Xor $x xor $y True if either $x or $y is true, but not both
&& And $x && $y True if both $x and $y are true
|| Or $x || $y True if either $x or $y is true
! Not !$x True if $x is not true

PHP String Operators

PHP has two operators that are specially designed for strings.

Operator Name Example Result Try it
. Concatenation $txt1 . $txt2 Concatenation of $txt1 and $txt2
.= Concatenation assignment $txt1 .= $txt2 Appends $txt2 to $txt1

PHP Array Operators

The PHP array operators are used to compare arrays.

Operator Name Example Result Try it
+ Union $x + $y Union of $x and $y
== Equality $x == $y Returns true if $x and $y have the same key/value pairs
=== Identity $x === $y Returns true if $x and $y have the same key/value pairs in the same order and of the same types
!= Inequality $x != $y Returns true if $x is not equal to $y
<> Inequality $x <> $y Returns true if $x is not equal to $y
!== Non-identity $x !== $y Returns true if $x is not identical to $y

PHP Conditional Assignment Operators

The PHP conditional assignment operators are used to set a value depending on conditions:

Operator Name Example Result Try it
?: Ternary $x = ? : Returns the value of $x.
The value of $x is if = TRUE.
The value of $x is if = FALSE
?? Null coalescing $x = ?? Returns the value of $x.
The value of $x is if exists, and is not NULL.
If does not exist, or is NULL, the value of $x is .
Introduced in PHP 7

Get Certified

COLOR PICKER

colorpicker

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: [email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail: [email protected]

Top Tutorials

Top references, top examples, get certified.

home

  • PHP Tutorial
  • Install PHP
  • PHP Echo vs Print
  • PHP Variable
  • PHP Variable Scope
  • PHP $ and $$
  • PHP Constants
  • PHP Magic Constants
  • PHP Data Types
  • PHP Operators
  • PHP Comments

Control Statement

  • PHP If else
  • PHP For Loop
  • PHP foreach loop
  • PHP While Loop
  • PHP Do While Loop
  • PHP Continue

PHP Programs

  • 20 PHP Programs
  • Sum of Digits
  • Prime Number
  • Table of Number
  • Armstrong Number
  • Palindrome Number
  • Fibonacci Series
  • Reverse Number
  • Reverse String
  • Swapping Two Numbers
  • Adding Two Numbers
  • Subtracting Two Numbers
  • Area of a Triangle
  • Area of Rectangle
  • Alphabet Triangle Method
  • Alphabet Triangle
  • Number Triangle
  • Star Triangle
  • PHP Functions
  • Parameterized Function
  • PHP Call By Value
  • PHP Call By Reference
  • PHP Default Arguments
  • PHP Variable Arguments
  • PHP Recursive Function
  • PHP Indexed Array
  • PHP Associative Array
  • Multidimensional Array
  • PHP Array Functions

PHP Strings

  • PHP String Functions
  • addcslashes()
  • addslashes()
  • chunk_split()
  • convert_cyr_string()
  • convert_uudecode()
  • convert_uuencode()
  • count_chars()
  • get_html_translation_table()
  • htmlentities()
  • html_entity_decode()
  • htmlspecialchars()
  • htmlspecialchars_decode()
  • Levenshtein()
  • localeconv()
  • md5_files()
  • metaphone()
  • money_format()
  • nl_langinfo()
  • number_format()
  • parse_str()
  • quoted_printable_decode()
  • quoted_printable_encode()
  • quotemeta()
  • setlocale()
  • sha1_file()
  • similar_text()
  • strcasecmp()
  • stripcslashes()
  • strncasecmp()
  • strnatcasecmp()
  • strnatcmp()
  • strtolower()
  • strtoupper()
  • str_getcsv()
  • str_ireplace()
  • str_repeat()
  • str_replace()
  • str_rot13()
  • str_shuffle()
  • str_split()
  • strip_tags()
  • str_word_count()
  • substr_compare()
  • substr_count()
  • substr_replace()
  • PHP Math Functions
  • PHP Form: Get Post

PHP Include

  • PHP include & require

State Management

  • PHP Session
  • PHP File Handling
  • PHP Open File
  • PHP Read File
  • PHP Write File
  • PHP Append File
  • PHP Delete File

Upload Download

  • PHP File Upload
  • PHP Download File
  • require_once
  • include_once
  • MVC Architecture
  • PHP vs. JavaScript
  • PHP vs. HTML
  • PHP vs. Node.js
  • PHP vs Python
  • Top 10 PHP frameworks
  • Count All Array Elements
  • Create Newline
  • Get Current Page URL
  • Remove First Element from Array
  • Remove Last Element from Array
  • Change Date Format
  • Get IP Address
  • PHP MySql Login System
  • var_dump() function
  • PHP Regular Expressions
  • preg_match() function
  • preg_replace() function
  • isset() function
  • print_r() function
  • Types of Errors in PHP
  • Display All Errors
  • PHP error_reporting
  • PHP header()
  • PHP unset() function
  • Get & Post Methods
  • Form Validation
  • Exception Handling in PHP
  • PHP try-catch
  • PHP Pagination
  • What is a Website
  • How to make a website
  • How to cite a website in APA format
  • How to cite a website in MLA format
  • How to download video from the website
  • PHP array_push
  • break vs continue in PHP
  • How to Install Composer on Windows
  • PHPMyAdmin Login
  • Creation of custom php.ini file in CPanel
  • Downgrade php 7.4 to 7.3 Ubuntu
  • Multiple File Upload using Dropzone JS in PHP
  • PHP Dropzone File Upload on Button Click
  • PHP find value in an array
  • PHP Codeigniter 3 Ajax Pagination using Jquery
  • How to Convert array into string in PHP
  • PHP Codeigniter 3 Create Dynamic Tree View using Bootstrap Treeview JS
  • CRUD Operation using PHP & Mongodb
  • PHP Ajax Multiple Image Upload
  • PHP Multidimensional Array Search By Value
  • PHP urlencode() Function
  • Image Gallery CRUD using PHP MySQL
  • How to get selected option value in PHP
  • Array to string conversion in PHP
  • PHP Contact Form
  • PHP string Concatenation
  • PHP Laravel 5.6 - Rest API with Passport
  • PHP compare dates
  • PHP Registration Form
  • PHP ternary operator
  • PHP basename() Function
  • Why do we need Interfaces in PHP
  • file_put_contents() Function in PHP
  • Is_array() Function in PHP
  • How to Use PHP Serialize() and Unserialize() Function
  • PHP Unset() vs Unlink() Function
  • PHP 5 vs PHP 7
  • PHP Imagearc() Function
  • PHP Imagecharup() Function
  • PHP Imagecolortransparent() Function
  • PHP Imagechar() Function
  • PHP Imagecreate() Function
  • PHP Imagecolorallocate() Function
  • PHP Image createtruecolor( ) Function
  • PHP Imagestring() Function
  • PHP Classes
  • Father of PHP
  • get vs post method in PHP
  • PHP append to array
  • fpassthru() Function in PHP
  • Imagick::borderImage() method in PHP
  • Imagick rotateImage() Function
  • Imagick transposeImage() Function
  • PHP Projects
  • Imagick floodFillPaintImage() Function
  • Imagick::charcoalImage() PHP
  • Imagick adaptiveBlurImage() Function
  • Imagick addImage() Function
  • Imagick addNoiseImage() Function
  • PHP Type Casting and Conversion of an Object to an Object of other class
  • PHP STR_CONTAINS()
  • Multiple Inheritance in PHP
  • What is a PHP Developer
  • PHP ob_start() Function
  • PHP Beautifier
  • PHP imagepolygon() Function
  • Free PHP Web Hosting
  • PHP Adminer
  • Polymorphism in PHP
  • PHP empty() Function
  • What is PHP-FPM
  • PHP STATIC VARIABLES
  • PHP IDE and Code Editor Software
  • PHP file_get_contents() Function
  • PHP sleep() Function
  • PHP GMP Functions Detail Reference
  • PHP gmp_abs() Function
  • PHP gmp_add() Function
  • PHP gmp_and()Functions
  • PHP GMP gmp_clrbit() Function
  • PHP GMP gmp_cmp() Function
  • PHP GMP gmp_com() Function
  • PHP gmp_div_q() Function
  • PHP gmp_div_qr() Function
  • PHP gmp_or() function
  • PHP gmp_divexact() Function
  • PHP gmp_export() Function
  • PHP gmp_fact() Function
  • PHP gmp_gcd() Function
  • PHP gmp_import() Function
  • PHP gmp_intval() Function
  • PHP gmp_invert() Function
  • PHP gmp_jacobi() Function
  • PHP gmp_legendre() Function
  • PHP gmp_mod() Function
  • PHP gmp_prob_prime() function
  • PHP gmp_random_bits() function
  • PHP gmp_random_range() function
  • PHP gmp_root() function
  • PHP gmp_rootrem() function
  • PHP gmp_random_seed() function
  • PHP gmp_scan0() function
  • PHP gmp_scan1() function
  • PHP gmp_setbit() function
  • PHP GMP gmp_testbit() Function
  • PHP gmp_random() function
  • PHP gmp_xor() function
  • How to create html table with a while loop in PHP
  • How to Encrypt or Decrypt a String in PHP
  • MySQLi CONNECT
  • MySQLi CREATE DB
  • MySQLi CREATE Table
  • MySQLi INSERT
  • MySQLi UPDATE
  • MySQLi DELETE
  • MySQLi SELECT
  • MySQLi Order by
  • PHP JSON Example

PHP OOPs Concepts

  • OOPs Concepts
  • OOPs Abstract Class
  • OOPs Abstraction
  • OOPs Access Specifiers
  • OOPs Const Keyword
  • OOPs Constructor
  • OOPs Destructor
  • Abstract vs Class vs Interface
  • Encapsulation
  • Final Keyword
  • OOPs Functions
  • OOPs Inheritance
  • OOPs Interface
  • OOPs Overloading
  • OOPs Type Hinting
  • Compound Types
  • PHP Integer
  • is_null() Function
  • PHP Boolean
  • Special Types
  • Inheritance Task
  • PHP Encryption
  • Two-way Encryption
  • Heredoc Syntax

Related Tutorials

  • MySQL Tutorial
  • WordPress Tutorial
  • CodeIgniter Tutorial
  • YII Tutorial
  • Laravel Tutorial
  • Magento 2 Tutorial

Interview Questions

  • PHP Interview
  • WordPress Interview
  • Joomla Interview
  • Drupal Interview
  • ftp_close()
  • ftp_connect()
  • ftp_chdir()
  • ftp_chmod()
  • ftp_alloc()
  • ftp_get_option()
  • ftp_delete()
  • ftp_login()
  • ftp_mkdir()
  • ftp_nb_continue()
  • ftp_nb_fget()
  • ftp_rename()
  • ftp_rmdir()

In this article, we will create a string concatenation in PHP. In this, we will learn the basics of PHP string. After that we will learn this concept with the help of various examples.

A string is a collection of characters. It offers various types of string operators and these operators have different functionalities such as string concatenation, compare values and to perform Boolean operations.

In , this operator is used to combine the two string values and returns it as a new string.

In the above example, we have concatenated the two strings in the third string. In this we have taken two variables $a and $b as a string type and $c variable is also string type in which the concatenate string is stored.

For this purpose we have used the Concatenation operator (.) to concatenate the strings.

Below figure demonstrates the output of this example:

In the above example, we have concatenated the two strings in the third string. In this we have taken two variables $fname and $lname as a string type and $c variable is also string type in which the concatenate string is stored.

For this purpose we have used the Concatenation operator (.) to concatenate the strings.

Below figure demonstrates the output of this example:

This operation appends the argument on the right side to the argument on the left side.

In the above example, we have concatenated the two strings in one string variable. In this we have taken a variable $string1 in which the concatenate string is stored. For this purpose we have used the Concatenation Assignment operator (".=") to concatenate the strings.

Below figure demonstrates the output of this example:

In the above example, we have concatenated the variable in the array string. In this we have taken a variable $a and & b string array in which the concatenate string is stored. For this purpose we have used the Concatenation Assignment operator (".=") to concatenate the strings.

Below figure demonstrates the output of this example:





Latest Courses

Python

We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks

Contact info

G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India

[email protected] .

Facebook

Latest Post

PRIVACY POLICY

Online Compiler

  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand
  • OverflowAI GenAI features for Teams
  • OverflowAPI Train & fine-tune LLMs
  • Labs The future of collective knowledge sharing
  • About the company Visit the blog

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Get early access and see previews of new features.

Concatante PHP variables inside loop by a "Concatenating Assignment Operator", and Echo each output loop separately

With the "Concatenating Assignment Operator" I assigned in the loop two variables. I need to get each loop result separately. The problem is that I don't know why each next loop result is copied to each next loop result.

Using this code, I get the output:

I'm working on making the output look like this:

Grzes's user avatar

  • 7 You need to reset $output at the top of the loop. –  aynber Commented Dec 1, 2021 at 14:14

You are always concatenating values to the $output, you never clear it, so the numbers are just continually added. All you need to do is change the first $output .= "1"; in to a $output = "1"; and that will have the effect of resetting $output to the one character ready to be concatenated with the second.

RiggsFolly's user avatar

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Sign up or log in

Post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .

Not the answer you're looking for? Browse other questions tagged php arrays while-loop or ask your own question .

  • The Overflow Blog
  • Masked self-attention: How LLMs learn relationships between tokens
  • Deedy Das: from coding at Meta, to search at Google, to investing with Anthropic
  • Featured on Meta
  • User activation: Learnings and opportunities
  • Preventing unauthorized automated access to the network
  • Feedback Requested: How do you use the tagged questions page?

Hot Network Questions

  • Does history possess the epistemological tools to establish the occurrence of an anomaly in the past that defies current scientific models?
  • Why do evacuations result in so many injuries?
  • Is there an error in the dissipation calculation of a mosfet?
  • When does derived tensor product commute with arbitrary products?
  • What is a "derivative security"?
  • what is the proper order for three verbs at the end of a sentence when there is no ersatz infinitive?
  • Can you find a grand tour of the rooms in this 12x12 grid?
  • How can I draw the intersection of a plane with a dome tent?
  • In big band horn parts, should I write double flats (sharps) or the enharmonic equivalent?
  • How do you measure exactly 31 minutes by burning the ropes?
  • Are logic and mathematics the only fields in which certainty (proof) can be obtained?
  • Do mathematicians care about the validity ("truth") of the axioms?
  • Why is my Lenovo ThinkPad running Ubuntu using the e1000e Ethernet driver?
  • How to jointly estimate range and delay of a target?
  • On a glassed landmass, how long would it take for plants to grow?
  • Estimating an upper bound of hyperbolicity constants in Gromov-hyperbolic groups
  • Code editor-script console missing
  • Story where the main character is hired as a FORTH interpreter. We pull back and realise he is a computer program living in a circuit board
  • How can I make second argument path relative to the first on a command?
  • Onto group actions and symmetries.
  • Is it ethical to edit grammar, spelling, and wording errors in survey questions after the survey has been administered, prior to publication?
  • What is an "axiomatic definition"? Every definition is an axiomatic definition?
  • How to Organise/Present Built Worlds?
  • Easily unload gravel from pickup truck

concatenation assignment operator php

COMMENTS

  1. PHP: String

    There are two string operators. The first is the concatenation operator ('.'), which returns the concatenation of its right and left arguments. The second is the concatenating assignment operator ('.= '), which appends the argument on the right side to the argument on the left side. Please read Assignment Operators for more information.

  2. PHP Concatenation Operators

    PHP Compensation Operator is used to combine character strings. Operator. Description. . The PHP concatenation operator (.) is used to combine two string values to create one string. .=. Concatenation assignment.

  3. PHP

    W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

  4. Concatenation of two strings in PHP

    In this article, we will concatenate two strings in PHP. There are two string operators. The first is the concatenation operator ('.'), which returns the concatenation of its right and left arguments. The second is the concatenating assignment operator ('.='), which appends the argument on the right side to the argument on the left side ...

  5. Concatenating Strings in PHP: Tips and Examples

    Here are some more advanced examples demonstrating the use of both the concatenation operator (.) and the concatenation assignment operator (.=) in PHP: ... while the concatenation assignment operator (.=) provides a convenient means of appending content to existing strings. This versatility is demonstrated through various examples, including ...

  6. PHP: Assignment

    Assignment Operators. The basic assignment operator is "=". Your first inclination might be to think of this as "equal to". Don't. It really means that the left operand gets set to the value of the expression on the right (that is, "gets set to").

  7. Mastering PHP String Concatenation: Essential Tips and Techniques for

    The concatenation assignment operator .= in PHP simplifies the process of appending one string to another by modifying the original string directly. This operator is especially useful in scenarios where a string needs to be built incrementally, such as in loops or when constructing complex messages dynamically.

  8. How to Concatenate Strings in PHP

    In this article, we will concatenate two strings in PHP. There are two string operators. The first is the concatenation operator ('.'), which returns the concatenation of its right and left arguments. The second is the concatenating assignment operator ('.='), which appends the argument on the right side to the argument on the left side. Examples:

  9. How to Concatenate Strings in PHP

    Use the Concatenation Assignment Operator to Concatenate Strings in PHP. In PHP, we can also use the concatenation assignment operator to concatenate strings. The concatenation assignment operator is .=. The difference between .= and . is that the concatenation assignment operator .= appends the string on the right side. The correct syntax to ...

  10. Learn to Concatenate Strings in PHP

    String concatenation refers to joining two or more strings to create a new string. It is a typical and helpful operation in PHP, allowing developers to create customized and dynamic strings by combining different sources. The dot (.) operator performs this operation in PHP by joining the strings and creating a new string.

  11. PHP Assignment Operators

    Use PHP assignment operator (=) to assign a value to a variable. The assignment expression returns the value assigned. Use arithmetic assignment operators to carry arithmetic operations and assign at the same time. Use concatenation assignment operator (.=)to concatenate strings and assign the result to a variable in a single statement.

  12. PHP

    Two string operands are concatenated returning the updated contents of string on the left side −. It will produce the following output −. PHP - String Operators - There are two operators in PHP for working with string data types: concatenation operator (.) and the concatenation assignment operator (.=). Read this chapter to learn how ...

  13. php

    3. Only slightly, since PHP has to parse the entire string looking for variables, while with concatenation, it just slaps the two variables together. So there's a tiny performance hit, but it's not noticeable for most things. It's a lot easier to concatenate variables like $_SERVER['DOCUMENT_ROOT'] using the concatenation operator (with quotes ...

  14. PHP String Operators(Concatenation) Tutorial

    There are two String operators in PHP. 1. Concatenation Operator "." (dot) 2. Concatenation Assignment Operator ".=" (dot equals) Concatenation Operator Concatenation is the operation of joining two character strings/variables together. In PHP we use . (dot) to join two strings or variables. Below are some examples of string concatenation:

  15. PHP >> Operators >> .=

    PHP » Operators » .= Syntax: $var .= expressionvarA variable.expressionA value to concatenate the variable with.Concatenation assignment operator.

  16. PHP Operators

    PHP Assignment Operators. The PHP assignment operators are used with numeric values to write a value to a variable. The basic assignment operator in PHP is "=". It means that the left operand gets set to the value of the assignment expression on the right.

  17. PHP string Concatenation

    There are two types of string operators provided by PHP. 1. Concatenation Operator ("."): In PHP, this operator is used to combine the two string values and returns it as a new string. Let's take the various examples of how to use the Concatenation Operator (".") to concatenate the strings in PHP. Example 1: <!

  18. php

    No way to do this with concatenation assignment operator. Share. Improve this answer. Follow answered Jul 13, 2015 at 12:29. Jordi Martín Jordi Martín. 519 4 4 silver ... Concatenation-assignment in PHP. 0. PHP Concatenation assignment. 0. PHP - Concatenate text to 2 variables in 1 operation. 1.

  19. Concatante PHP variables inside loop by a "Concatenating Assignment

    With the "Concatenating Assignment Operator" I assigned in the loop two variables. I need to get each loop result separately. The problem is that I don't know why each next loop result is ... PHP 'foreach' array concatenate echo. 0. How to print multiple variables values using loop. 0. PHP Combine arrays in a loop. 1. Concatenate array on loop ...