Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views15 pages

Lecture 4 PHP

Uploaded by

maxida6992
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views15 pages

Lecture 4 PHP

Uploaded by

maxida6992
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Course Name: PHP Framework

Topic: Introduction of PHP


Prepared By: Gaurav Jain
Department of Computer Science and Engineering
CONTENTS

Introduction of Unit

PHP Operator.

PHP Expression.

Basic Programs.
Objectives


This unit introduces the basics of PHP as a server-side scripting
language for web development. It covers PHP Operator,
Expressions in PHP, Basic Program.

By the end, learners will have a solid foundation for more
advanced PHP programming and dynamic web development.
Course Outcomes


This course enables learners to understand PHP’s role in
server-side web development, PHP Operator , Expressions in
PHP, Basic Program. By Students will also evaluate PHP’s
performance and usability, building a strong foundation for
advanced programming and dynamic web applications.
OPERATORS IN PHP?
 PHP supports a number of operations like arithmetic
operations, logical operations, Bitwise Operations, Execution
Operations, and much more.

 PHP Operator is a symbol i.e. used to perform operations on


operands. In simple words, operators are used to perform
operations on variables or values. For example:

 $num=10+20;//+ is the operator and 10,20 are operands

 In the above example, + is the binary + operator, 10 and 20


are operands and $num is variable. After evaluating, the
output will be 30.
OPERATORS IN PHP?
Arithmetic Operators in PHP:-

We use Arithmetic operators to perform mathematical operations like addition, subtraction,


multiplication, division, etc. on the given operands.
Operator Description Example

+ Adds two operands $a + $b = 62

- Subtracts second operand from the first $a - $b = 22

* Multiply both operands $a * $b = 840

/ Divide numerator by de-numerator $a / $b = 2.1

Modulus Operator and remainder of after an integer


% $a % $b = 2
division

++ Increment operator, increases integer value by one $a ++ = 43

Decrement operator, decreases integer value by


-- $a -- = 42
one
OPERATORS IN PHP?
Example’s:-

<?php
$a = 12;
$b = 4;
// Here, we are performing Arithmetic operations one by one
// and displaying the output
echo "Addition is: " . ($a + $b) . "\n"; //Performing the addition operation
echo "Subtraction is: " . ($a - $b) . "\n"; //
Performing the subtraction operation
echo "Multiplication is: " . ($a * $b) . "\n"; //
Performing the multiplication operation
echo "Division is: " . ($a / $b) . "\n"; //Performing the division operation
echo "Modulus is: " . ($a % $b) . "\n"; //
Performing the modulus operation
echo "Exponentiation is: " . ($a ** $b); //
OPERATORS IN PHP?
Comparison Operators in PHP:-

You would use Comparison operators to compare two operands and find the
relationship between them.
Operator Description Example

Checks if the value of two operands


== are equal or not, if yes then condition ($a == $b) is not true
becomes true.
Checks if the value of two operands
!= are equal or not, if values are not ($a != $b) is true
equal then condition becomes true.
Checks if the value of left operand is
greater than the value of right
> ($a > $b) is false
operand, if yes then condition
becomes true.
Checks if the value of left operand is
< less than the value of right operand, if ($a < $b) is true
yes then condition becomes true.
Checks if the value of left operand is
greater than or equal to the value of
>= ($a >= $b) is false
right operand, if yes then condition
becomes true.
Checks if the value of left operand is
less than or equal to the value of right
<= ($a <= $b) is true
operand, if yes then condition
becomes true.
OPERATORS IN PHP?
Example’s:-
<?php
$FirstNum = 6;
$SecondNum = 3;

if ($FirstNum == $SecondNum) {
echo "Case 1 : FirstNum is equal to SecondNum \n";
} else {
echo "Case 1 : FirstNum is not equal to SecondNum \n";
}
?>
OPERATORS IN PHP?
Logical Operators in PHP:-
You can use Logical operators in PHP to perform logical operations on
multiple expressions together. Logical operators always return Boolean
values, either trueOperator
or false.
Description Example

Called Logical AND operator. If both the operands


and (A and B) is true
are true then condition becomes true.

Called Logical OR Operator. If any of the two


or operands are non zero then condition becomes (A or B) is true
true.

Called Logical AND operator. If both the operands


&& (A && B) is true
are non zero then condition becomes true.

Called Logical OR Operator. If any of the two


|| operands are non zero then condition becomes (A || B) is true
true.

Called Logical NOT Operator. Use to reverses the


! logical state of its operand. If a condition is true !(A && B) is false
then Logical NOT operator will make false.
OPERATORS IN PHP?
Example’s:-

<?php
$a = 40;
$b = 20;

if ($a && $b) {


echo "CASE 1 : Both a and b are true \n";
} else {
echo "CASE 1 : Either a or b is false \n";
}
?>
OPERATORS IN PHP?
Assignment Operators in PHP:-

The right-hand side of the assignment operator holds the value and the
left-hand side of the assignment operator is the variable to which the
Operator Description Example

value will
=
be assigned.
Simple assignment operator, Assigns values from right side operands to left side operand
C = A + B will assign value of A + B into
C

Add AND assignment operator, It adds right operand to the left operand and assign the result to left
+= operand
C += A is equivalent to C = C + A

Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result
-= to left operand
C -= A is equivalent to C = C - A

Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result
*= to left operand
C *= A is equivalent to C = C * A

Divide AND assignment operator, It divides left operand with the right operand and assign the result to
/= left operand
C /= A is equivalent to C = C / A

Modulus AND assignment operator, It takes modulus using two operands and assign the result to left
%= operand
C %= A is equivalent to C = C % A
OPERATORS IN PHP?
Example’s:-
<?php
$x = 24;
$y = 12;

$z = $x + $y;
echo "Addition is: $z \n";

$z += $x;
echo "Result of Add and Assignment Operators: $z \n";

$z -= $x;
echo "Result of Subtract and Assignment Operators: $z \n";

$z *= $x;
echo "Result of Multiply and Assignment Operators: $z \n";

$z /= $x;
echo "Result of Division and Assignment Operators: $z \n";

$z %= $x;
echo "Result of Modulus and Assignment Operators: $z";
?>
OPERATORS IN PHP?
String Operators in PHP:-

The "." (dot) operator is PHP's concatenation operator. It joins two string
operands (characters of right-hand string appended to left hand string)
and returns a new string.

PHP also has the ".=" operator which can be termed as the concatenation
assignment operator. It updates the string on its left by appending the
Operator Name Example Explanation
characters of right-hand operand.
. Concatenation $a . $b Concatenate both
$a and $b
.= Concatenation and $a .= $b First concatenate
Assignment $a and $b, then
assign the
concatenated string
to $a, e.g. $a =
OPERATORS IN PHP?
Example’s:-

<?php
$a = "T";
$b = "point" . " ";
$c = "Tech!";
echo $a . $b . $c, "\n";
$a .= $b . $c;
echo $a;
?>
Thank You!!

You might also like