Professional Documents
Culture Documents
My PHP CompiledByYashPatil
My PHP CompiledByYashPatil
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>PHP Tutorial</title>
</head>
<body>
<div class="container">
This is my first php website
</div>
</body>
</html>
To Print In php
<?php
echo "Hello world and this is printed using PHP";
?>
Variable In php
Variables are nothing more than a container for holding the values in it. In PHP,
you can create a variable by including the “ $ “ before declaring it.
$variable1 = 5;
$variable2 = 2;
echo $variable1;
echo $variable2;
PHP is a dynamically typed language, meaning here, you don’t have to declare the
data types. PHP is not case sensitive that means classes, functions, and user-
defined functions are not case sensitive
Operators In pHp
Operators are used to performing operations on variables. Operators are symbols that tell the
PHP processor to perform certain actions. For example, the addition (+) symbol is an operator
that tells PHP to add two variables or values, while the greater-than (>) symbol is an operator
that tells PHP to compare two values.
Arithmetic Operators
// Arithmetic Operators
echo "<br>";
echo "The value of varible1 + variable2 is ";
echo $variable1 + $variable2;
echo "<br>";
echo "The value of varible1 - variable2 is ";
echo $variable1 - $variable2;
echo "<br>";
echo "The value of varible1 * variable2 is ";
echo $variable1 * $variable2;
echo "<br>";
echo "The value of varible1 / variable2 is ";
echo $variable1 / $variable2;
echo "<br>";
Assigment Operators
PHP Assignment Operators
These are used to assign a value from one variable to another
Operator Description Example Result
= Assign $x = $y $x = $y
+= Add and assign $x += $y $x = $x + $y
-= Subtract and assign $x -= $y $x = $x - $y
*= Multiply and assign $x *= $y $x = $x * $y
/= Divide and assign quotient $x /= $y $x = $x / $y
The following example will show you these arithmetic operators in action:
The left operand gets set to the value of the expression on the right
x = y
Copy
x += y
Addition
x = x + y
Copy
x -= y
Subtraction
x = x - y
Copy
x *= y
Multiplication
x = x * y
Copy
x /= y
Division
x = x / y
Copy
x %= y
Modulus
x = x % y
// Comparison Operators
// echo "<h1> Comparison Operators </h1>";
echo "The value of 1==4 is ";
Copy
Comparison can be used in if-else statements.
Here var_dump() holds type and value of the variable(s).
Pre-increment (++i) − Before assigning the value to the variable, the value is
incremented by one.
Post-increment (i++) − After assigning the value to the variable, the value is
incremented.
Operator Name Effect
++$x Pre-increment Increments $x by one, then returns $x
$x++ Post-increment Returns $x, then increments $x by one
--$x Pre-decrement Decrements $x by one, then returns $x
$x-- Post-decrement Returns $x, then decrements $x by one
// Increment/Decrement Operators
// echo $variable1++;
// echo $variable1--;
// echo ++$variable1;
echo --$variable1;
// Logical Operator
// and (&&)
// or (||)
// xor
// !