Why PHP
Why PHP
Why PHP
<?PHP?>
Course Structure
2 Parts
1. Introduction to PHP (3 Days)
Introduction to PHP
Day-1 : PHP installations, PHP Language Basics, Basic Control Structures
Day-2 : Advanced control Structures, Function, Arrays, Include &
Require(Modularity)
Day-3 : PHP with HTML: HTTP Get & Post, Sessions, Cookies, Strings and
String Functions,
Tools
Code
Application
Why
PHP
Popularity
visitors per
month)
Front-end
(Client-side)
Back-end
(Server-side)
Database
Facebook.c
1,100,000,000 JavaScript
om
MariaDB, MySQL, H
Hack, PHP
(HHVM), Python, C++, BaseCassandra
YouTube.co
1,100,000,000 JavaScript
m
Yahoo
JavaScript
PHP
MySQL, PostgreSQL
JavaScript
Oracle Database
JavaScript
PHP , Hack
MySQL, MariaDB
750,000,000
Amazon.co
500,000,000
m
Wikipedia.or
475,000,000
g
About
PHP
About PHP
PHP originally stood for Personal Home Page, but it now stands for the
recursive acronym PHP: Hypertext Preprocessor.
Setting Up
Development
Environment
Intallations
WAMP Server (Windows Apache
Mysql Php) -
VC++ (VC110)
Notepad++
Runtime
: Code Editor
Language Basics
PHP
The echo statement can be used with or without parentheses: echo or echo().
<?php
?>
Variables
They are "containers" (spaces in memory) that hold data. The data can
be changed, thus it is called "variable".
PHP is dynamically typed, because the type of the variable is linked to
the value of the variable. You could define a variable for a string, store a
string, and then replace the string with a number.
To do the same thing in C#/Java, you would have to cast, or change
the type of, the variable, and store it in a different "container".
All variables in PHP follow the format of a dollar sign ($) followed by an
identifier i.e. $variable_name.
These identifiers are case-sensitive, meaning that capitalization
matters, so $wiki is different from $Wiki.
Variables
PHP has eight data types which we use to construct our variables
Resources are special variables that hold references to resources external to PHP
(such as database connections).
Variables
Example:
<?php
$x = 5;
$y = 4;
echo $x + $y;
?>
Global Variable
Global Variable
Example:
<?php
$somevar = 15;
function addit()
{
GLOBAL $somevar;
$somevar++;
print "Somevar is $somevar";
}
addit();
?>
Operators
= (assignment)
*= (multiplication assignment)
+ (addition)
/= (division assignment)
(subtraction)
%= (modulus assignment)
* (multiplication)
.= (concatenation assignment)
/ (division)
% (modulus)
. (concatenation)
= (subtraction assignment)
Assignment operators :
+= (addition assignment)
(decrement)
Conditional Operators
Operator
Description
Example
==
Checks if the value of two operands are equal or not, if yes then
condition becomes true.
(A == B) is not
true.
===
Checks if the value and type of two operands are equal or not, if
yes then condition becomes true.
(A === B) is not
true.
!=
Checks if the value of two operands are equal or not, if values are (A != B) is true.
not equal then condition becomes true.
>
(A > B) is not
true.
<
Checks if the value of left operand is less than the value of right
operand, if yes then condition becomes true.
(A < B) is true.
>=
(A >= B) is not
true.
<=
(A <= B) is true.
Logical Operators
Operator
Description
Example
and
Called Logical AND operator. If both the operands are true then
condition becomes true.
(A and B) is true.
or
(A or B) is true.
&&
Called Logical AND operator. If both the operands are non zero
then condition becomes true.
(A && B) is true.
||
(A || B) is true.
PHP
IF statement
<?php
$foo = 1;
$bar = 2;
if ($foo == $bar) {
echo "$foo is equal to $bar.";
}
elseif ($foo > $bar) {
echo "$foo is greater than $bar.";
}
else {
echo "$foo is less than $bar.";
}
?>
FOR Loop
<?php
$a = 0;
$b = 0;
for( $i = 0; $i<5; $i++ )
{
$a += 10;
$b += 5;
}
echo ("At the end of the loop a = $a and b = $b" );
?>
WHILE Loop
<?php
$i = 0;
$num = 50;
while( $i < 10)
{
$num--;
$i++;
}
echo ("Loop stopped at i = $i and num = $num" );
?>
Do While Loop
<?php
$i = 0;
$num = 0;
do
{
$i++;
}
while( $i < 10 );
echo ("Loop stopped at i = $i" );
?>
Break
<?php
$i = 0;
while( $i < 10)
{
$i++;
if( $i == 3 )
break;
}
echo ("Loop stopped at i = $i" );
?>
Continue
<?php
$array = array(
foreach( $array
{
if( $value ==
continue;
echo "Value
}
?>
1, 2, 3, 4, 5);
as $value )
3 )
is $value <br />";
Thanks