Escolar Documentos
Profissional Documentos
Cultura Documentos
Evolution of PHP
Zeev and Andi rewrote the PHP core yet again, calling
it the Zend Engine .
What is PHP ?
Dynamic Pages
Scripting Language
Uses of PHP
Uses of PHP
Supports OOP
<?php
and the last part is :
?>
Using Comments
Multiline comments
// This is a Comment.
/*This is
a MultiLine
Comment. */
Variables
Variables Contd
Examles:
Constants
define("ROOT_LOCATION",
"/usr/local/www/");
$directory = ROOT_LOCATION;
Constants Cont
Examples:
__LINE__ : The current line number of the
file.
Constants Contd
Example :
echo "This is line ".__LINE__." of file
".__FILE__;
Arrays
There are two types of array :
Basic Array
Associative Array
Arrays Cont
Basic Array :
$myArray[1] = 'two';
Arrays Cont
Associative Array :
$birthdays =
array('Kevin' => '1978-04-12', Amy'
=>'1980-05-16);
$birthdays['Kevin'] = '1978-04-12';
echo 'My birthday is: '. $birthdays['Kevin'];
Data Types
Type Example
1. Boolean true
2. Integer 5
3. Float or Double
4. String hello
5. Object
6. Array
7. NULL
3.234
Data Types
Examples of test functions :
is_null();
is_int();
is_double();
is_array();
is_bool();
<?php
$testing;
echo "is null? ".is_null($testing);
?>
Arithmetic Operators
Operator
Description
Addition
Subtraction
Multiplication
/
%
Division
Modulus
++
Increment
Decrement
Example
$j + 1
$j - 6
$j * 11
$j / 4
$j % 9
++$j
$j
Assignment Operators
Operator
=
+=
Example
$j =15
$j +=5
-=
$j -=3
*=
$j *=8
/=
.=
%=
$j /=16
$j .=$k
$j %=4
Equivalent to
$j = 15
$j = $j + 5
$j = $j - 3
$j = $j * 8
$j = $j / 16
$j = $j . $k
$j = $j % 4
String Concatenation
Comparison Operators
Operator Description Example
== Is equal to
$j ==4
=== Is identical to
$j === 4
!= Is not equal to
$j !=21
>
Is greater than
<
Is less than
$j >3
$j <100
$j >=15
$j <=8
Comparison Operators
Operator
Description Example
$j < 5 || $j > 10
Exclusive or
$j xor $k
if else Statement
if (expression) {
// code to execute if the expression
evaluates to true
} else {
// code to execute in all other cases
}
if elseifelse Statement
if (expression) {
// code to execute if the expression
evaluates to true
} elseif (another expression) {
// code to execute if the previous
expression failed
// and this one evaluates to true
} else {
// code to execute in all other cases
}
switch Statement
switch (expression) {
case result1:
// execute this if expression results in result1
break;
case result2:
// execute this if expression results in result2
break;
default:
// execute this if no break statement
// has been encountered hitherto
}
while Loop
for Loop
while Loop
while (expression) {
// do something
}
<?php
$counter = 1;
while ($counter <= 6) {
echo $counter." times 2 is ".($counter * 2)."<br />";
$counter++;
}
?>
for Loop
for (initialization expression; test expression; modification
expression) {
// code to be executed
}
<?php
for ($counter=1; $counter<=6; $counter++) {
echo $counter." times 2 is ".($counter* 2)."<br/>";
}
?>
Functions
Functions Contd
Two types of Functions
Built in functions
Functions Contd
Built in functions
some_function($an_argument,$another_argument);
strtoupper("Hello Web!");
Functions Contd
User defined functions
function
some_function($argument1,$argument2) {
//function code here
}
Functions Contd
User defined functions
function printMe($txt)
{
echo $txt."<br/>";
}
Functions Contd
User defined functions
<?php
function addNums($firstnum, $secondnum)
{
$result= $firstnum + $secondnum;
return $result;
}
echo addNums(3,5); //will print 8
?>
ADVANCED PHP
Class :
Define what an object looks like, what
information it can store, and what
actions and calculations it can perform.
class MyClassname {
}
OOP IN PHP
Properties:
OOP IN PHP
Methods:
OOP IN PHP
Methods:
To access a property of the class in a method use:
$this->someProperty
OOP IN PHP
Constructors:
OOP IN PHP
Constructors:
mysql
PDO
mysqli