Geshan Manandhar Developer, Young Innovations Pvt. Limited
Geshan Manandhar Developer, Young Innovations Pvt. Limited
PHP
http://www.php.net
Geshan Manandhar
Developer,
Young Innovations Pvt. Limited
www.geshanmanandhar.com
GeshanManandhar.com 1
Variables in PHP
► Boolean: It can be either TRUE or FALSE.
► Integer: The size of an integer is platform-
dependent, although a maximum value of
about two billion is the usual value.
► Float: The size of a float is platform-
dependent, although a maximum of
~1.8e308 with a precision of roughly 14
decimal digits is a common value
GeshanManandhar.com 2
Variable in PHP
► String: A string is series of characters. In
PHP, a character is the same as a byte, that
is, there are exactly 256 different characters
possible.
► Array: An array in PHP is actually an ordered
map. A map is a type that maps values to
keys.
$names[1] = “Ram”;
$names[2] = “Shyam”;
GeshanManandhar.com 3
Variables in PHP
► Objects:mainly have attributes and
functions.
<?php
class test
{
function do_test()
{
echo "Testing class function.";
}
}
GeshanManandhar.com 7
Comparison Operators
GeshanManandhar.com 8
Increment Decrement Operators
► ++ and --
Code at Day02\prog09_inc_dec_operator.php
GeshanManandhar.com 9
Logical Operator
GeshanManandhar.com 10
String Operator
►. used to concatenate strings
► .= used to append a string.
<?php
$b = ”Hello” . "World!"; // now $b contains "Hello
World!"
$a = "Hello ";
$a .= "World!"; // now $a contains "Hello World!"
?>
GeshanManandhar.com 11
If-else if- else
<?php
$a=10;
$b=17;
GeshanManandhar.com 14
While Loop
<?php
$i = 1;
while ($i <= 10) {
echo $i++;
}
GeshanManandhar.com 16
For Loop
<?php
for ($i = 1; $i <= 10; $i++) {
echo $i;
}
GeshanManandhar.com 18
PHP simple Function
<?php <body>
function adder($var1, $var2) <?php
{
$a=10;
$sum = $var1+$var2;
$b=15;
return $sum;
} $added = adder($a, $b);
?> ?>
<html> The sum of <?=$a?> and <?
<head> =$b?> is <?=$added?>.
<title>Function with PHP an </body>
example</title> </html>
</head>
GeshanManandhar.com 19
Lets get rolling
► Write a program that performs all arithmetic
operations with 3 variables.
► Get the month with date(“F”) function and
if its December and day date(“d”) is greater
than 20 and less than 26, print “Merry
Christmas”.
► Print multiplication table of 5 with for loop.
► Use foreach loop for an array called names
and print the names in the array with its
keys. GeshanManandhar.com 20
Questions are welcome
► That’s why god gave us two eyes, two ears but
only one mouth.
GeshanManandhar.com 21