|
Assignement operators in php |
This is tutorial of Assignment Operators in PHP With Examples.We have already seen a glimpse about these operators in previous 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 Assigment Operator Screenshot1 |
<?php
$number1 = 10;
$number1 += 2;
echo $number1;
?>
Output (Screenshot2):-
|
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):-
|
Code for Assignment operator Screenshot3 |
<?php
$number1 = 10;
$number1 -= 2;
echo $number1;
?>
output (Screenshot4):-
|
Screenshot4 |
Similarly as above, we can decrements its value by taking $number1 -= 2.
Code for Assignment operators (Screenshot5):-
|
Screenshot5 |
<?php
$number1 = 10;
$number1 *= 2;
echo $number1;
?>
output (screenshot6):-
|
Screenshot6 |
Multiplication variables with Assignment Operators
Code for Assignment operators (Screenshot7):-
|
Screenshot7 |
<?php
$number1 = 10;
$number1 /= 2;
echo $number1;
?>
output (screenshot8):-
|
Screenshot8 |
Dividing variables with Assignment Operators
Code for Concatenate and Assignment operators (Screenshot9):-
|
Screenshot9 |
<?php
$text = 'Hello';
$text .= 'World';
echo $text;
?>
output (Screenshot10) :-
|
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.
No comments:
Post a Comment
Thanks For Comment Will get you Soon..