0% found this document useful (0 votes)
17 views

PHP Tizag Tutorial-16 PDF

The document discusses string operators and combination arithmetic assignment operators in PHP. The period "." operator is used to concatenate strings. The += and -= operators are commonly used to increment or decrement a variable by a fixed amount, providing a shorthand for operations like $counter = $counter + 1. Other combination operators like *=, /=, %=, and .= perform arithmetic or concatenation assignment in a single operation.

Uploaded by

Anil Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

PHP Tizag Tutorial-16 PDF

The document discusses string operators and combination arithmetic assignment operators in PHP. The period "." operator is used to concatenate strings. The += and -= operators are commonly used to increment or decrement a variable by a fixed amount, providing a shorthand for operations like $counter = $counter + 1. Other combination operators like *=, /=, %=, and .= perform arithmetic or concatenation assignment in a single operation.

Uploaded by

Anil Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

String Operators

As we have already seen in the Echo Lesson, the period "." is used to add two strings together, or more
technically, the period is the concatenation operator for strings.

PHP Code:
$a_string = "Hello";
$another_string = " Billy";
$new_string = $a_string . $another_string;
echo $new_string . "!";

Display:
Hello Billy!

Combination Arithmetic & Assignment Operators

In programming it is a very common task to have to increment a variable by some fixed amount. The most
common example of this is a counter. Say you want to increment a counter by 1, you would have:

• $counter = $counter + 1;

However, there is a shorthand for doing this.

• $counter += 1;

This combination assignment/arithmetic operator would accomplish the same task. The downside to this
combination operator is that it reduces code readability to those programmers who are not used to such an
operator. Here are some examples of other common shorthand operators. In general, "+=" and "-=" are the
most widely used combination operators.
Operator English Example Equivalent Operation
+= Plus Equals $x += 2; $x = $x + 2;
-= Minus Equals $x -= 4; $x = $x - 4;
*= Multiply Equals $x *= 3; $x = $x * 3;
/= Divide Equals $x /= 2; $x = $x / 2;
%= Modulo Equals $x %= 5; $x = $x % 5;
.= Concatenate Equals $my_str.="hello"; $my_str = $my_str . "hello";

You might also like