| Assignment Operators in php |
This is tutorial of Assignment Operators in PHP With Examples.We have already seen a glimpse about these operators inprevious tutorials eg. $number1 = 10; In this “equal to(=)” is assignment operator in php that is assigning value to number1 here sign “=” is not comparing variables but its assigning value to variables.
Code for Assignment operators (Screenshot1):-
1
2
3
4
5
6
7
8
9
| <?php$number1 = 10;$number1 += 2;echo $number1;?> |
output (Screenshot2):-
In this example,we are assigning variable $number1 = 10 and we can increment its value by taking $number1 += 2 ,which is an easy way to write code and its known as assignment operators.
Code for Assignment operators (Screenshot3):-
1
2
3
4
5
6
7
8
9
| <?php$number1 = 10;$number1 -= 2;echo $number1;?> |
output (Screenshot4):-
Similarly as above, we can decrement its value by taking$number1 -= 2.
Code for Assignment operators (Screenshot5):-
Code for Assignment operators (Screenshot5):-
1
2
3
4
5
6
7
8
9
| <?php$number1 = 10;$number1 *= 2;echo $number1;?> |
output (screenshot6):-
Multiplication variables with Assignment Operators
Code for Assignment operators (Screenshot7):-
Code for Assignment operators (Screenshot7):-
1
2
3
4
5
6
7
8
| <?php<pre>$number1 = 10;$number1 /= 2;echo $number1;?> |
output (screenshot8):-
Dividing variables with Assignment Operators
Code for Concatenate and Assignment operators (Screenshot9):-
Code for Concatenate and Assignment operators (Screenshot9):-
1
2
3
4
5
6
7
8
9
| <?php$text = 'Hello';$text .= 'World';echo $text;?> |
output (Screenshot10) :-
In this we can concatenate with assignment operators.
$text .= ‘ World’;
concatenate with $text = ‘ Hello’
instead of this, we can write $text = ‘Hello’.'World’;.
This is example of how to concatenate string with other string using assignment operators.This are basic examples of assignment operators and how we can assign values of different variables or plain text itself in php.
$text .= ‘ World’;
concatenate with $text = ‘ Hello’
instead of this, we can write $text = ‘Hello’.'World’;.
This is example of how to concatenate string with other string using assignment operators.This are basic examples of assignment operators and how we can assign values of different variables or plain text itself in php.
Read More On Extra Tutorials
No comments:
Post a Comment