Professional Documents
Culture Documents
OVERVIEW OF PHP
Overview contd..
PHP arrays are merge of the arrays of common programming lang and
associative arrays and having characteristics of both.
PHP has an extensive library of funs. Making it more flexible and more
powerful tool for server side s/w development.Many predefined
functions are used to provide the interfaces to other s/w systems such
as mails and DBs
and
contin
ue
elseif
foreac
h
includ or
e
switc virtua
h
l
break
default
extend
s
Functio
n
list
requir
e
this
xor
case
do
false
global
new
return
true
while
class
else
for
If
not
static
var
Primitives
PHP has 8 primitive data types.(fundamental)
PHP has 4 scalar types.(single)
Boolean
integer
double
string
Two compound types
Array and
objects
And Two special types
Resources (used to link)and
NULL
VARIABLES
Dynamically typed and no type declaration.
The type is set every time it is assigned a value.
An unassigned variables is called unbound variables which has the value NULL.
If an unbound variable is used in an expression and uses a number then NULL is
0.,If it is a string then NULL is empty string.
IsSet function is used to test whether a variable is currently has a value or not.
Eg. IsSet($fruit) returns true if it has a value. False otherwise.
A variable retains it value until either it is assigned a new value or it is set back
to the unassigned state by unset function.
Error reporting function is used to inform about the reference of unbound
variable
Place this statement at the beginning of script
error_reporting(15);
The default error repoting is 7 which will not report the use of unbound
variables.
Integer Type:
Double type :
Corresponds to double type of C
String type :
Boolean type
PREDEFINED FUNCTIONS
FUNCTION
PARAMETER
TYPE
RETURNS
floor
double
ceil
double
round
double
Nearest integer
srand
integer
rand
Two
numbers
abs
number
min
One or more
smallest
String operations
Functio
n
Parameter
type
Returns
strlen
A string
strcmp
Two strings
strpos
Two strings
substr
A string and
an integer
chop
A string
trim
A string
itrim
A string
strtolow
er
A string
Ex for strpos
<?php
Echo strpos(I love PHP,PHP);
?>
output 7
Ex for substr
$ str = apples are good;
$sub = substr($str,7,1);
Output
$sub = a
gettype function
Assignment operators:
OUTPUT
Any output from a PHP scripts becomes part of the
document the PHP procesor is building .So all the output
must be in the form of Xhtml which may include embedded
client script.
%6d
printf(Today is 6s :,$day);
then
CONTROL STATEMENTS
PHP control statements are similar to those of C and its
descendants.
PHP uses the 8 relational operators of javascript.
< ,<= , > , >= , != , == , === and !==
The === produces true only if both operands are of the same
type and have same value and !== ,the opposite of===.
If the type of operands of the other 6 relational operators are
not the same ,one is coerced into other type.
If a string is compared to a number , the string can be converted
to the number and the numeric comparision will be done.
Ther are 6 boolean operators.
and , or , xor , ! , && , ||
The precedence of and , or is lower than the && and ||
SELECTION STATEMENTS :
The control statement can be either an individual
statement or a compound statement .An if statement
can include any number of elseif classes.
Ex.
if ($day == Saturday || $day == Sunday)
$today = weekend;
else {
$today = weekday ;
$work = true;
}
LOOP STATEMENTS:
while , do-while , for , foreach are similar to javascript
ARRAYS
2nd method:
$list = array(10,20,25,45,34)
This assignments create the array of 5 elements with keys 0
,1, 2, 3,4
For E.g
$stuff = array(make => cessna , model => c20 ,
2 =>sold);
Array elements can accessed by subscripting. The value in
the subscript is the key of the value being referenced,
Ex :
$ages[mary] = 36;
The value of the element whose key is mary in the ages
array is set to 36
Multiple elements of an array can be assigned to scalar
variables in one assignment
$trees = array(oak , pine , binary);
$list($hardwood , $softwood, $datastructures) = $trees;
Now, $hardwood = oak $softwood = pine and
$datastructures=binary
Now,
$str has are you fine
Internally the elements of the array are stored in a linked
list of cells where each cell includes both the key and the
value of the element.
The cells themselves are stored in memory through a
hashing functions so that they are randomly distributed.
String keys are implemented through the hashing
function.
Key based
access
function
Hash
fun
Key value
Sequenti
next al access
fun
Key value
next
Key value
next