02php vars op control etc
TRANSCRIPT
-
8/14/2019 02PHP Vars OP Control Etc
1/21
GeshanManandhar.com 1
Day 2Day 2
PHPPHP
Geshan ManandharGeshan Manandhar
Developer,Developer,Young Innovations Pvt. LimitedYoung Innovations Pvt. Limited
www.geshanmanandhar.comwww.geshanmanandhar.com
http://www.php.net
-
8/14/2019 02PHP Vars OP Control Etc
2/21
GeshanManandhar.com 2
Variables in PHPVariables in PHP
Boolean: It can be eitherBoolean: It can be either TRUETRUE oror FALSEFALSE..
Integer: The size of an integer is platform-Integer: The size of an integer is platform-
dependent, although a maximum value ofdependent, although a maximum value of
about two billion is the usual value.about two billion is the usual value.Float: The size of a float is platform-Float: The size of a float is platform-
dependent, although a maximum ofdependent, although a maximum of
~1.8e308 with a precision of roughly 14~1.8e308 with a precision of roughly 14decimal digits is a common valuedecimal digits is a common value
-
8/14/2019 02PHP Vars OP Control Etc
3/21
GeshanManandhar.com 3
Variable in PHPVariable in PHP
String: A string is series of characters.String: A string is series of characters.In PHP, a character is the same as aIn PHP, a character is the same as abyte, that is, there are exactly 256byte, that is, there are exactly 256
different characters possible.different characters possible.Array: An array in PHP is actually anArray: An array in PHP is actually an
ordered map. A map is a type thatordered map. A map is a type that
mapsmaps valuesvalues toto keyskeys.. $names[1] = Ram;$names[1] = Ram; $names[2] = Shyam;$names[2] = Shyam;
-
8/14/2019 02PHP Vars OP Control Etc
4/21
GeshanManandhar.com 4
Variables in PHPVariables in PHP
Objects: mainly have attributes andObjects: mainly have attributes andfunctions.functions.
?>
-
8/14/2019 02PHP Vars OP Control Etc
5/21
GeshanManandhar.com 5
Naming variables in PHPNaming variables in PHP
Variables in PHP are represented by a dollar signVariables in PHP are represented by a dollar signfollowed by the name of the variable. The variablefollowed by the name of the variable. The variablename is case-sensitive.name is case-sensitive.
A valid variable name starts with a letter orA valid variable name starts with a letter or
underscore, followed by any number of letters,underscore, followed by any number of letters,numbers, or underscores.numbers, or underscores. $a_5=10; //valid$a_5=10; //valid
$#b = 20; //invalid$#b = 20; //invalid
Predefined Variables ($_SERVER, $_POST)Predefined Variables ($_SERVER, $_POST)
-
8/14/2019 02PHP Vars OP Control Etc
6/21
GeshanManandhar.com 6
ConstantConstant
You can define a constant by using the define()You can define a constant by using the define()-function. Once a constant is defined, it can never-function. Once a constant is defined, it can neverbe changed or undefined.be changed or undefined.
?>
-
8/14/2019 02PHP Vars OP Control Etc
7/21
GeshanManandhar.com 7
Arithmetic OperatorsArithmetic Operators
See Program for more clarification:Day02\prog06_Operators.php
-
8/14/2019 02PHP Vars OP Control Etc
8/21
GeshanManandhar.com 8
Comparison OperatorsComparison Operators
See code of Day02\prog08_comparision_operators.php
-
8/14/2019 02PHP Vars OP Control Etc
9/21
GeshanManandhar.com 9
Increment DecrementIncrement Decrement
OperatorsOperators ++ and --++ and --
Code at Day02\prog09_inc_dec_operator.php
-
8/14/2019 02PHP Vars OP Control Etc
10/21
GeshanManandhar.com 10
Logical OperatorLogical Operator
-
8/14/2019 02PHP Vars OP Control Etc
11/21
GeshanManandhar.com 11
String OperatorString Operator
. used to concatenate strings. used to concatenate strings
.= used to append a string..= used to append a string.
?>
-
8/14/2019 02PHP Vars OP Control Etc
12/21
GeshanManandhar.com 12
If-else if- elseIf-else if- else
?>
-
8/14/2019 02PHP Vars OP Control Etc
13/21
GeshanManandhar.com 13
If-else if- else alternateIf-else if- else alternate
?>
-
8/14/2019 02PHP Vars OP Control Etc
14/21
GeshanManandhar.com 14
Switch ExampleSwitch Example
?>
-
8/14/2019 02PHP Vars OP Control Etc
15/21
GeshanManandhar.com 15
While LoopWhile Loop
?>
-
8/14/2019 02PHP Vars OP Control Etc
16/21
GeshanManandhar.com 16
Do While LoopDo While Loop
?>
-
8/14/2019 02PHP Vars OP Control Etc
17/21
-
8/14/2019 02PHP Vars OP Control Etc
18/21
GeshanManandhar.com 18
For Each loopFor Each loop
?>
-
8/14/2019 02PHP Vars OP Control Etc
19/21
GeshanManandhar.com 19
PHP simple FunctionPHP simple Function
?>
Function with PHPFunction with PHPan examplean example
?>
The sum of andThe sum of and is is .=$added?>.
-
8/14/2019 02PHP Vars OP Control Etc
20/21
GeshanManandhar.com 20
Lets get rollingLets get rolling
Write a program that performs all arithmeticWrite a program that performs all arithmeticoperations with 3 variables.operations with 3 variables.
Get the month with date(F) function and if itsGet the month with date(F) function and if itsDecember and day date(d) is greater than 20December and day date(d) is greater than 20
and less than 26, print Merry Christmas.and less than 26, print Merry Christmas.Print multiplication table of 5 with for loop.Print multiplication table of 5 with for loop.
Use foreach loop for an array called names andUse foreach loop for an array called names andprint the names in the array with its keys.print the names in the array with its keys.
-
8/14/2019 02PHP Vars OP Control Etc
21/21
GeshanManandhar.com 21
Questions are welcomeQuestions are welcome
Thats why god gave us two eyes, two earsThats why god gave us two eyes, two earsbut only one mouth.but only one mouth.