Professional Documents
Culture Documents
Learning PHP By: Eyad Alshareef
Learning PHP By: Eyad Alshareef
Learning PHP
By: Eyad Alshareef
Eyad Alshareef
19.1 Introduction
PHP is
Eyad Alshareef
open source.
Eyad Alshareef
Example 1
Eyad Alshareef
Comments in PHP
Eyad Alshareef
In PHP, all user-defined functions, classes, and keywords (e.g. if, else,
while, echo, etc.) are NOT case-sensitive.
In the example below, all three echo statements below are legal (and
equal):
Eyad Alshareef
PHP 5Variables
A variable starts with the $ sign, followed by the name of the variable
Variable names are case sensitive ($y and $Y are two different
variables)
Eyad Alshareef
All
Eyad Alshareef
Eyad Alshareef
Eyad Alshareef
The scope of a variable is the part of the script where the variable can be
referenced/used.
local
global
static
Eyad Alshareef
Eyad Alshareef
PHP Strings
A string can be any text inside quotes. You can use single or double quotes:
Eyad Alshareef
PHP Integers
Integers can be specified in three formats: decimal (10-based), hexadecimal (16based - prefixed with 0x) or octal (8-based - prefixed with 0)
The PHP var_dump() function returns the data type and value of variables
Eyad Alshareef
PHP
Booleans
Booleans
$x=true;
$y=false;
Eyad Alshareef
The special NULL value represents that a variable has no value. NULL is the
only possible value of data type NULL.
The NULL value identifies whether a variable is empty or not. Also useful to
differentiate between the empty string and null values of databases.
Eyad Alshareef
PHP 5Operators
Eyad Alshareef
Eyad Alshareef
Eyad Alshareef
Eyad Alshareef
<?php
if ($a > $b) {
echo "a is bigger than b";
} elseif ($a == $b) {
echo "a is equal to b";
} else {
echo "a is smaller than b";
}
?>
Eyad Alshareef
Switch
Eyad Alshareef
While Loops
While (condition)
{
Statements;
}
<?php
$count=0;
While($count<3)
{
Print hello PHP. ;
$count += 1;
// $count = $count + 1;
// or
// $count++;
?>
Eyad Alshareef
Functions
Eyad Alshareef
Functions example
<?php
function sum($x,$y) {
$z=$x+$y;
return $z;
}
echo "5 + 10 = " . sum(5,10) . "<br>";
echo "7 + 13 = " . sum(7,13) . "<br>";
echo "2 + 4 = " . sum(2,4);
?>
Eyad Alshareef
Eyad Alshareef
Eyad Alshareef
Eyad Alshareef
Eyad Alshareef