Assignment Operator in PHP
Notes:
PHP Assignment Operator
Assignment Operator: is used to initialize or assign a value to variable or a constant.
=
Short Hand Arithmetic Assignment operators:
+=, -=, *=, /=, %=, and **=
Example code:
const PI = 3.142;
echo "PI=",PI, "<br/>"; // PI=3.142
$a = 10;
echo "a=",$a,"<br/>"; // a=10
$a = 20;
echo "a=",$a,"<br/>"; // a=20
$a += 10; // $a = $a + 10;
echo "a=",$a,"<br/>"; // a=30
$a-=10; // $a = $a - 10;
echo "a=",$a,"<br/>"; // a=20
$a*=2; // $a = $a * 2;
echo "a=",$a,"<br/>"; // a=40
$a/=2; // $a = $a / 2;
echo "a=",$a,"<br/>"; // a=20
$a%=2; // $a = $a % 2;
echo "a=",$a,"<br/>"; // a=0
$a += 10; // $a = $a + 10;
echo "a=",$a,"<br/>"; // a=10
$a **= 2; // $a = $a ** 2;
echo "a=",$a,"<br/>"; // a=100
Interview Questions:
1. PHP stands for ______________
a. Hypertext Preprocessor
b. Preprocessor Hypertext
c. Personal Home Processor
d. Personal Hypertext processor
Ans: a