Operators, Concatenation, Comments
Hello All...
welcome every one. I'm going to start PHP lectures for Very Beginners, who
wants to learn PHP from very beginning. No matter if you do not have any basic
programming concept. If you follow my tutorials I hope you will surely get some
how good knowledge of PHP.
Today our
Topic is
OPERATORS
There are
four types of operators
1- Arithmetic
Operator
a. Addition (+)
b. Subtraction (-)
c. Multiplication
(*)
d. Division (/)
e. Modulus (%)
2- Assignment
Operator
a. =
b. +=
c. -=
d. *=
e. /=
f. .=
g. %=
3- Comparison
Operator
a. is equal to (==)
b. is not equal to (!=)
c. is not equal to (<>)
d. is greater than (>)
e. is less than (<)
f. is greater than
or equal to (>=)
g. is less than or
equal to (<=)
4- Logical Operator
a. AND ( && )
b. OR ( || )
c. NOT ( ! )
Increment/decrement Operators
Increment
operator ++
Increment operator adds +1 to the
given value
Decrement
operator –
Decrement operator subtracts the -1
from the given value.
Example:
<?php
$a = 10;
$a++;
echo $a;
// the
result will be 11. Increment operator adds 1 to the variable.
$b = 5;
$b--;
echo $b;
// the
result will be 4. Decrement operator subtracts -1 from the variable;
?>
Concatenation
Concatination means to combine
something. Here in almost each programming language we use concatenation to
combine two parts or two statements as to result as a single statement. Here is
an example:
<?php
$var1
= “hello this is an example”;
$var2
= “of concatenation”;
echo
$var1 . $var2;
// this will result as `hello this is
an exampleof concatenation`
?>
to give space between exampleof words
just apply space at the end of first variable or from the first of second
variable, within quotations.
Comments
Comments are used by developers in
order to know about his code that for what purpose this code is about. Comments
are also very useful for the end users if he/she will see the comments besides
the code he/she will surely know that what you have written in your code, and
what’s logic developer has applied in it. Comments will not affect your code
even if you write between your code just place double forward slash `//` before
you start writing comment or another way is to write this `/* */` between these
you must write comment whatever you want to write in your comment.
// comment is known as Single line
Comment
/*
is known as multiline comment.
Whatever we will write between this
will not affect our */
It’s very good approach to use
comments for every important part of code.
Thanks Guys.
Any thing missing or any question from this topic you can comment below, I will
be trying to solve and answer your question.
Our Next
topic will be `Conditions`.
Good Luck J
No comments:
Post a Comment