Saturday, 19 October 2013

Assignment Operators in php

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.
Assignment Operators in php
Assignment Operators(Screenshot1)
Code for Assignment operators (Screenshot1):-
1
2
3
4
5
6
7
8
9
<?php
 
$number1 = 10;
 
$number1 += 2;
 
echo $number1;
 
?>
output (Screenshot2):-
Assignment Operators in php
Assignment Operators(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):-
Assignment Operators in php
Assignment Operators(Screenshot3)
1
2
3
4
5
6
7
8
9
<?php
 
$number1 = 10;
 
$number1 -= 2;
 
echo $number1;
 
?>
output (Screenshot4):-
Assignment Operators in php
Assignment Operators(Screenshot4)
Similarly as above, we can decrement its value by taking$number1 -= 2.
Code for Assignment operators (Screenshot5):-
Assignment Operators in php
Assignment Operators(Screenshot5)
1
2
3
4
5
6
7
8
9
<?php
 
$number1 = 10;
 
$number1 *= 2;
 
echo $number1;
 
?>

output (screenshot6):-
Assignment Operators in php
Assignment Operators(Screenshot6)
Multiplication variables with Assignment Operators
Code for Assignment operators (Screenshot7):-
Assignment Operators in php
Assignment Operators(Screenshot7)
1
2
3
4
5
6
7
8
<?php
<pre>$number1 = 10;
 
$number1 /= 2;
 
echo $number1;
 
?>

output (screenshot8):-
Assignment Operators in php
Assignment Operators(Screenshot8)
Dividing variables with Assignment Operators
Code for Concatenate and Assignment operators (Screenshot9):-
Assignment Operators in php
Assignment Operators(Screenshot9)
1
2
3
4
5
6
7
8
9
<?php
 
$text = 'Hello';
 
$text .= 'World';
 
echo $text;
 
?>
output (Screenshot10) :-
Assignment Operators in php
Assignment Operators(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.

Read More On Extra Tutorials

No comments:

Post a Comment