Concatenating Assignment Operator

¡Supera tus tareas y exámenes ahora con Quizwiz!

During assignment, the computer will first evaluate everything to the right of the assignment operator and return a single value.

In the code above, the computer will concatenate the strings "Aisle" and " Nevertell" into the value "Aisle Nevertell".

One theme you may notice as you learn a programming language's syntax is that common actions that programmers need to do a lot often have a shortcut. Consider the following:

In the code above, we have the variable $full_name assigned the value "Aisle". We want to reassign $full_name to its current value appended with the string " Nevertell".

It will then assign this string as the value to the $full_name variable.

This is true even for more complex operations:

Believe it or not, this is such a common task that PHP offers a shorthand notation, the concatenating assignment operator (.=). Let's compare the same action but using this alternate operator:

It may seem funny to provide a shortcut to save just a few characters of typing, but when operations are performed often enough, those keystrokes can really add up. This syntax is also faster and easier to read which makes code easier to maintain.

One important thing to note is that even though PHP is often flexible about whitespace, it is inflexible with the concatenating assignment operator—the . and = characters must not have any spaces or other whitespace characters between them.

One important thing to note is that even though PHP is often flexible about whitespace, it is inflexible with the concatenating assignment operator—the . and = characters must not have any spaces or other whitespace characters between them.

Concatenating Assignment Operator

We can assign and reassign variables to the values that result from operations:


Conjuntos de estudio relacionados

Spring 2016 Chapter 19 Cardiovascular System:Blood Vessels HCC A & P II

View Set

CRA conflict of interest and Bioethics

View Set

A&P one- Mcampbell- unit 3 smartbook 11

View Set

Chapter 38 Vehicle Extrication and Special Rescue quiz

View Set

The Sympathetic and Parasympathetic Nervous Systems

View Set

bowel, ATI: Urinary & Bowel Elimination, Fundamentals of Nursing chapter 38, funds chap 38, Bowel sound P.U., Ch 38 Bowel Elimination, Chapter 38: Bowel Elimination, Ch 38 Bowel Elimination taylor NCLEX, PrepU Ch38 Bowel Elimination, Chapter 38: Bowe...

View Set

development part 1 practice questions

View Set

Physical Science Lab Equipment Identification

View Set