Introduction To PHP
Introduction To PHP
PHP
String
Integer
Float
Boolean
Object
Array
Null
DEFINITIONS AND EXAMPLES
PHP String
Example:
<?php
$a = 100;
Var_dump ($a);
?>
PHP FLOAT
Example:
<?php
$b = 29.76;
Var_dump ($b);
?>
PHP BOOLEAN
Example;
<?php
$a = 40;
$b = 70;
Var_dump ($a > $b);
?>
PHP ARRAY
Example:
<?php
$car = array(“Volvo”, “BMW”, “Toyota”);
Var_dump ($car);
?>
PHP OBJECT
i. Arithmetic Operators
ii. Assignment Operators
iii. Comparison Operators
iv. Increment / Decrement Operators
v. Logical Operators
vi. String Operators
vii. Array Operators
viii. Conditional assignment Operators
PHP – THE IF STATEMENT
Syntax :
If (condition) {
code to be executed if condition is true;
}
Example:
<?php
$a = data(“H”);
if ($a <“20”){
echo “Have a good day!”;
}
?>
PHP –THE IF—ELSE STATEMENT
The if – else statement executes some code if one condition is true and another condition is
false.
Syntax:
If (condition){
Code to be executed if condition is true;
}else{
Code to be executed if condition is false;
}
Example:
<?php
$a = data(“H”);
if ($a <“20”){
echo “Have a good day!”;
} else{
echo “Have a bad day!”;
}
?>
PHP - THE - IF -ELSE--IF STATEMENT
The if-else--if statement executes different codes for more than one
conditions.
Example:
<?php
$a = data(“H”);
if ($a <“20”){
echo “Have a good day!”;
} else{
echo “Have a bad day!”;
}else if{
echo “Have a good night!”;
}
?>
PHP LOOPS
Often when you write code, you want the some block of
code to run over again a certain number of times , so
instead of adding several almost equal code-lines a script ,
we can use loops.
Loops are use to execute the some block code again as long
as a certain condition is true.
TYPES OF LOOPS
Example:
<?php
$x = 1;
while ($x <=5){
echo “The number is $x <br>”;
$x++;}
?>
PHP FUNCTIONS
<?php
Function write Msg() {
echo “Hello World!”;
}
Write Msg();//call the function
?>
Example:
<?php
Function family Name($ fname) {
echo “$ fname Refsnes,<br>”;
}
Family Name(“Jenni”);
Family Name(“Hege”);
Family Name(“Stale”);
?>
PHP GLOBAL VARIABLE SUPER GLOBES
Super global were introduction in PHP 4.1.0, and are built-
in variable that are always available in all scape.
$_REQUEST
$_POST
$_GET
$_FILES
$_ENV
$_COOKIE
$_SESSION
GET VS POST