SlideShare a Scribd company logo
Introduction to PHP
•Server-Side Scripting
•MYSQL
•PHP
•Apache
•Variables
•Control Structure
•Looping
A “script” is a collection of program or sequence of
instructions that is interpreted or carried out by
another program rather than by the computer
processor.
Client-side
Server-side
In server-side scripting, (such as PHP, ASP) the script
is processed by the server Like:
Apache, ColdFusion, ISAPI and Microsoft's IIS on
Windows.
Client-side scripting such as JavaScript runs on the
web browser.
 Advantages of Server-Side Scripting

 Dynamic content.
 Computational capability.
 Database and file system access.
 Network access (from the server only).
 Built-in libraries and functions.
 Known platform for execution (as opposed to client-

side, where the platform is uncontrolled.)
 Security improvements
• PHP stands for PHP: Hypertext Preprocessor
• Developed by Rasmus Lerdorf in 1994
• It is a powerful server-side scripting language for

creating dynamic and interactive websites.
• It is an open source software, which is widely
used to develop dynamic websites.
• It is an efficient alternative to competitors such as
Microsoft's ASP.
• PHP is perfectly suited for Web development and

can be embedded directly into the HTML code.
• The PHP syntax is very similar to JavaScript, Perl
and C.
• PHP is often used together with Apache (web
server) on various operating systems. It also
supports ISAPI and can be used with Microsoft's
IIS on Windows.
• PHP supports many databases
(MySQL, Informix, Oracle, Sybase, Solid, Postgre
SQL, Generic ODBC, etc.)
• What is a PHP File?
• PHP files have a file extension of

".php", ".php3", or ".phtml"
• PHP files can contain text, HTML tags and scripts
• PHP files are returned to the browser as plain
HTML
What you need to develop PHP Application:
• Install Apache (or IIS) on your own server, install
PHP, and MySQL
• OR
• Install Wampserver2 (a bundle of
PHP, Apache, and MySql server) on your own
server/machine
• When a PHP document is requested of a

server, the server will send the document first to a
PHP processor
• Two modes of operation
– Copy mode in which plain HTML is copied to the

output
– Interpret mode in which PHP code is interpreted
and the output from that code sent to output
– The client never sees PHP code, only the output
produced by the code
• PHP statements are terminated with semicolons ;
• Curly braces, { } are used to create compound statements
• Variables cannot be defined in a compound statement

unless it is the body of a function
• PHP has typical scripting language characteristics
–
–
–
–

Dynamic typing, un-typed variables
Associative arrays
Pattern matching
Extensive libraries

• Primitives, Operations, Expressions
– Four scalar types: boolean, integer, double, string
– Two compound types: array, object
– Two special types: resource and NULL
• A PHP scripting block always starts with <?php and ends with

?>
<?php ……………. ?>
– Other options are:
1.
<? ……………… ?>
2.
<script> ... </script>

• There are three basic statements to output text with PHP:

echo, print, and printf. Example:
echo 'This is a <b>test</b>!';
• Comments:
– #
– //
– /* . . . */
Basic PHP Syntax
 Inserting external files:
 PHP provides four functions that enable

you to insert code from external files:
include() or require() include_once()
or require_once() functions.
• E.g.
 include("table2.php");
– Included files start in copy mode
Example 1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head> <title>Simple PHP Example</title>

<body>

<?php
echo "Hello Class of 2011. This is my first PHP Script";
echo "<br />";
print "<b><i>What have you learnt and how many friends have you
made?</i></b>";
echo "<br /><a href='PHP I-BSIC.ppt'>PHP BASIC</a>";

?>
</body>
</html>
PHP Variables
• Variables are used for storing values, such as

numbers, strings or function results, so that they can be
used many times in a script.
• All variables in PHP start with a $ sign symbol.
• Variables are assigned using the assignment operator "="
• Variable names are case sensitive in PHP: $name is not

the same as $NAME or $Name.
• In PHP a variable does not need to be declared before

being set.
• PHP is a Loosely Typed Language.
Strings in PHP
•
•
•

a string is a sequence of letters, symbols, characters and arithmetic values or
combination of all tied together in single or double quotes.
String literals are enclosed in single or double quotes
Example:
<?php
$sum = 20;
echo 'the sum is: $sum';
echo "<br />";
echo "the sum is: $sum";
echo "<br />";
echo '<input type="text" name="first_name" id="first_name">';
?>

–

Double quoted strings have escape sequences (such as /n or /r) interpreted
and variables interpolated (substituted)
– Single quoted strings have neither escape sequence interpretation nor variable
interpolation
– A literal $ sign in a double quoted string must be escaped with a backslash, 
– Double-quoted strings can cover multiple lines
PHP Function
 In php a function is a predefined set of

commands that are carried out when the function
is called.
 The real power of PHP comes from its functions.
 PHP has more than 700 built-in or predefine
functions for you to use.
Using Built-in Function
 Examples: Inserting external files:
 PHP provides four functions that enable you to insert code from external

files: include() or require() include_once() or require_once()
functions.
 A sample include file called add.php
<html> <body>
<?php
function add( $x, $y ) {
return $x + $y; }
?>
<h1>Welcome to my home page</h1>
<p>Some text</p>
</body> </html>

Using the include function
<?php
include('add.php');
echo add(2, 2); ?>
PHP Functions - Adding
parameters
 A parameter is just like a variable.
 The parameters are specified inside the parentheses.

Syntax:
<?php
function function_name(param_1, ...
, param_n)
{
statement_1;
statement_2;
...
statement_m;

?>

}

return return_value;
PHP Functions - Adding
parameters
 Functions can also be used to return values.
Example:



<html>
<body>








<?php
function add($x,$y)
{
$total = $x + $y;
return $total;
}




echo "1 + 16 = " . add(1,16);
?>




</body>
</html>
Control Structure
 Control structures are the building blocks of any

programming language. PHP provides all the
control structures that you may have encountered
anywhere. The syntax is the same as C or Perl.
 Making computers think has always been the
goal of the computer architect and the
programmer. Using control structures computers
can make simple decisions and when
programmed cleverly they can do some complex
things.
PHP Switch Statement
• If you want to select one of many blocks of code to be

executed, use the Switch statement.
• The switch statement is used to avoid long blocks of
if..elseif..else code.
Syntax
switch (expression)
{
case label1: code to be executed if expression = label1;
break;
case label2: code to be executed if expression = label2;
break;
default: code to be executed if expression is different from both
label1 and label2;
}
PHP Switch Statement















switch ($textcolor)
{
case "black":
echo "I'm black";
break;
case "blue":
echo "I'm blue";
break;
case "red":
echo "I'm red";
break;
default: // It must be something else
echo "too bad!!, I'm something else";
}
PHP Looping
• Looping statements in PHP are used to execute the

same block of code a specified number of times.
• In PHP we have the following looping statements:
– while - loops through a block of code if and as long as

a specified condition is true
– do...while - loops through a block of code once, and
then repeats the loop as long as a special condition is
true
– for - loops through a block of code a specified number
of times
– foreach - loops through a block of code for each
element in an array
The while Statement
Syntax
while (condition)
{
// statements

}

Example
<html> <head> <title>Let us count !!!</title></head>
<body>
<?php
$limit = 10;
echo "<h2> Let us count from 1 to $limit </h2><br />";
$count = 1;
while ($count <= $limit)
{
echo "counting $count of $limit <br>";
$count++;
}
?>
</body>
<html>
The do...while Statement
•

The do...while statement will execute a block of code at least once - it
then will repeat the loop as long as a condition is true.

Syntax
• do { code to be executed; } while (condition);









Example
<html> <body>
<?php
$i=0;
do { $i++; echo "The number is " . $i . "<br />"; }
while ($i<5);
?>
</body> </html>
PHP Arrays
 An array can store one or more values in a single

variable name.
 There are three different kind of arrays:
 Numeric array - An array with a numeric ID key
 Associative array - An array where each ID key is

associated with a value
 Multidimensional array - An array containing one
or more arrays
Numeric Array
• A numeric array stores each element with a numeric ID

key.
• There are different ways to create a numeric array:
Example 1
• In this example the ID key is automatically assigned:
• $names = array("Peter","Quagmire","Joe");
Example 2
• In this example we assign the ID key manually:
$names[0] = "Peter";
$names[1] = "Quagmire";
$names[2] = "Joe";
Associative Arrays
• Each ID key is associated with a value.
• When storing data about specific named values, a

numerical array is not always the best way to do it.
• There are two ways of creating Associative Array:
Example 1
• $ages =
array("Peter"=>32, "Quagmire"=>30, "Joe"=>34);
Example 2
• $ages['Peter'] = "32"; $ages['Quagmire'] = "30";
$ages['Joe'] = "34";
Multidimensional Arrays
• In a multidimensional array, each element in the main array can

also be an array. And each element in the sub-array can be an
array, and so on.
• Example 1
• with automatically assigned ID keys:

$families = array
( "Griffin"=>array
( "Peter", "Lois", "Megan" ),

"Quagmire"=>array
( "Glenn" ),

"Brown"=>array
( "Cleveland", "Loretta", "Junior" )

);
Multidimensional Arrays



Example 2:
The array above would look like this if written to the output:





Array
(
[Griffin] => Array
 (
 [0] => Peter
 [1] => Lois
 [2] => Megan
 )
[Quagmire] => Array
 (
 [0] => Glenn
 )
[Brown] => Array
 (
 [0] => Cleveland
 [1] => Loretta
 [2] => Junior )
 )





•

displaying a single value from the array above:



echo "Is " . $families['Griffin'][2] . " a part of the Griffin family?";

More Related Content

PPT
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PPTX
Operators php
PDF
Operators in PHP
PDF
Data Types In PHP
PPT
PHP variables
PPSX
Php using variables-operators
PPT
Basic PHP
PDF
Functions in PHP
PHP - DataType,Variable,Constant,Operators,Array,Include and require
Operators php
Operators in PHP
Data Types In PHP
PHP variables
Php using variables-operators
Basic PHP
Functions in PHP

What's hot (20)

PPT
Php i basic chapter 3
PDF
Php Tutorials for Beginners
PPTX
Basic of PHP
PPTX
Lesson 4 constant
PPT
Class 3 - PHP Functions
PPTX
Learn PHP Basics
PPT
Class 2 - Introduction to PHP
ODP
Php variables (english)
PPTX
PHP Basics
PPTX
Lesson 2 php data types
PPTX
php basics
PPTX
PHP Powerpoint -- Teach PHP with this
ODP
PHP Basic
ODP
PHP Web Programming
PPT
Introduction to PHP
PPTX
PHP Basics
PPT
PHP Workshop Notes
PPTX
Php introduction
PPT
Php Chapter 2 3 Training
Php i basic chapter 3
Php Tutorials for Beginners
Basic of PHP
Lesson 4 constant
Class 3 - PHP Functions
Learn PHP Basics
Class 2 - Introduction to PHP
Php variables (english)
PHP Basics
Lesson 2 php data types
php basics
PHP Powerpoint -- Teach PHP with this
PHP Basic
PHP Web Programming
Introduction to PHP
PHP Basics
PHP Workshop Notes
Php introduction
Php Chapter 2 3 Training
Ad

Viewers also liked (15)

PPT
Charting solutions evaluation-1
PPTX
Pathos presentation
PDF
Double cartridge seal
PPT
Liquid properties
PPT
Internet by Javiera.
PPT
Ci powerpoint
PPTX
Best spring classes in navi mumbai,spring course-provider in navi-mumbai,spri...
DOC
adarsh resume
PDF
Aix admin-course-provider-navi-mumbai
PPT
E&C Вrodaband 2015 Власть перезагрузка создание коммуникациинной платформы дл...
PPT
PDF
Introduction to BluWrap
PPTX
Unit 5 proses 1 function and ability group 5
PPTX
Siebel training-course-navi-mumbai-siebel-course-provider-navi-mumbai
Charting solutions evaluation-1
Pathos presentation
Double cartridge seal
Liquid properties
Internet by Javiera.
Ci powerpoint
Best spring classes in navi mumbai,spring course-provider in navi-mumbai,spri...
adarsh resume
Aix admin-course-provider-navi-mumbai
E&C Вrodaband 2015 Власть перезагрузка создание коммуникациинной платформы дл...
Introduction to BluWrap
Unit 5 proses 1 function and ability group 5
Siebel training-course-navi-mumbai-siebel-course-provider-navi-mumbai
Ad

Similar to Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,best php-mysql classes in navi-mumbai (20)

PPT
PHP - Introduction to PHP Fundamentals
PDF
Wt unit 4 server side technology-2
PPT
PPTX
introduction to php and its uses in daily
PPT
php 1
PPT
PHP and MySQL.ppt
PPT
Prersentation
PDF
Introduction to PHP - Basics of PHP
PPTX
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
PDF
WT_PHP_PART1.pdf
PPTX
Web Application Development using PHP Chapter 1
PPT
php41.ppt
PPT
PHP InterLevel.ppt
PPT
php-I-slides.ppt
PPT
Php i-slides
PPT
Php i-slides
PPT
Php i-slides (2) (1)
PPT
Php i-slides
PDF
PHP in Web development and Applications.pdf
PPT
introduction to php web programming 2024.ppt
PHP - Introduction to PHP Fundamentals
Wt unit 4 server side technology-2
introduction to php and its uses in daily
php 1
PHP and MySQL.ppt
Prersentation
Introduction to PHP - Basics of PHP
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
WT_PHP_PART1.pdf
Web Application Development using PHP Chapter 1
php41.ppt
PHP InterLevel.ppt
php-I-slides.ppt
Php i-slides
Php i-slides
Php i-slides (2) (1)
Php i-slides
PHP in Web development and Applications.pdf
introduction to php web programming 2024.ppt

More from anshkhurana01 (15)

DOCX
sas-course-provider-navi-mumbai-sas-training-navi-mumbai-sas-classes-navi-mumbai
TXT
PPTX
Aix admin-course-provider-navi-mumbai
PPTX
Websphere application-server-training-course-navi-mumbai-websphere-applicatio...
PPTX
Shell scripting-training-course-navi-mumbai-shell-scripting-course-provider-n...
PDF
Linux training-course-navi-mumbai-linux-course-provider-navi-mumbai
PDF
Java j2ee-training-course-navi-mumbai-java-j2ee-course-provider-navi-mumbai
PDF
Siebel training-course-navi-mumbai-siebel-course-provider-navi-mumbai
PDF
Tibco training-course-navi-mumbai-tibco-course-provider-navi-mumbai
PDF
Embeddedsystem training-course-navi-mumbai-embeddedsysteml-course-provider-na...
PDF
Mainframe training-course-navi-mumbai-mainframe-course-provider-navi-mumbai
PDF
Sas training-course-navi-mumbai-sas-course-provider-navi-mumbai
PDF
Linux training-course-navi-mumbai-linux-course-provider-navi-mumbai
PPT
Mysql classes in navi-mumbai,mysql course-provider-in-navi-mumbai
PPTX
Best java courses in navi mumbai best classes for java in navi mumbai-java cl...
sas-course-provider-navi-mumbai-sas-training-navi-mumbai-sas-classes-navi-mumbai
Aix admin-course-provider-navi-mumbai
Websphere application-server-training-course-navi-mumbai-websphere-applicatio...
Shell scripting-training-course-navi-mumbai-shell-scripting-course-provider-n...
Linux training-course-navi-mumbai-linux-course-provider-navi-mumbai
Java j2ee-training-course-navi-mumbai-java-j2ee-course-provider-navi-mumbai
Siebel training-course-navi-mumbai-siebel-course-provider-navi-mumbai
Tibco training-course-navi-mumbai-tibco-course-provider-navi-mumbai
Embeddedsystem training-course-navi-mumbai-embeddedsysteml-course-provider-na...
Mainframe training-course-navi-mumbai-mainframe-course-provider-navi-mumbai
Sas training-course-navi-mumbai-sas-course-provider-navi-mumbai
Linux training-course-navi-mumbai-linux-course-provider-navi-mumbai
Mysql classes in navi-mumbai,mysql course-provider-in-navi-mumbai
Best java courses in navi mumbai best classes for java in navi mumbai-java cl...

Recently uploaded (20)

PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Classroom Observation Tools for Teachers
PPTX
Cell Structure & Organelles in detailed.
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
RMMM.pdf make it easy to upload and study
Final Presentation General Medicine 03-08-2024.pptx
A systematic review of self-coping strategies used by university students to ...
Chinmaya Tiranga quiz Grand Finale.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
VCE English Exam - Section C Student Revision Booklet
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Final Presentation General Medicine 03-08-2024.pptx
Microbial disease of the cardiovascular and lymphatic systems
Microbial diseases, their pathogenesis and prophylaxis
2.FourierTransform-ShortQuestionswithAnswers.pdf
Classroom Observation Tools for Teachers
Cell Structure & Organelles in detailed.
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Complications of Minimal Access Surgery at WLH
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
RMMM.pdf make it easy to upload and study

Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,best php-mysql classes in navi-mumbai

  • 1. Introduction to PHP •Server-Side Scripting •MYSQL •PHP •Apache •Variables •Control Structure •Looping
  • 2. A “script” is a collection of program or sequence of instructions that is interpreted or carried out by another program rather than by the computer processor. Client-side Server-side In server-side scripting, (such as PHP, ASP) the script is processed by the server Like: Apache, ColdFusion, ISAPI and Microsoft's IIS on Windows. Client-side scripting such as JavaScript runs on the web browser.
  • 3.  Advantages of Server-Side Scripting  Dynamic content.  Computational capability.  Database and file system access.  Network access (from the server only).  Built-in libraries and functions.  Known platform for execution (as opposed to client- side, where the platform is uncontrolled.)  Security improvements
  • 4. • PHP stands for PHP: Hypertext Preprocessor • Developed by Rasmus Lerdorf in 1994 • It is a powerful server-side scripting language for creating dynamic and interactive websites. • It is an open source software, which is widely used to develop dynamic websites. • It is an efficient alternative to competitors such as Microsoft's ASP.
  • 5. • PHP is perfectly suited for Web development and can be embedded directly into the HTML code. • The PHP syntax is very similar to JavaScript, Perl and C. • PHP is often used together with Apache (web server) on various operating systems. It also supports ISAPI and can be used with Microsoft's IIS on Windows. • PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, Postgre SQL, Generic ODBC, etc.)
  • 6. • What is a PHP File? • PHP files have a file extension of ".php", ".php3", or ".phtml" • PHP files can contain text, HTML tags and scripts • PHP files are returned to the browser as plain HTML
  • 7. What you need to develop PHP Application: • Install Apache (or IIS) on your own server, install PHP, and MySQL • OR • Install Wampserver2 (a bundle of PHP, Apache, and MySql server) on your own server/machine
  • 8. • When a PHP document is requested of a server, the server will send the document first to a PHP processor • Two modes of operation – Copy mode in which plain HTML is copied to the output – Interpret mode in which PHP code is interpreted and the output from that code sent to output – The client never sees PHP code, only the output produced by the code
  • 9. • PHP statements are terminated with semicolons ; • Curly braces, { } are used to create compound statements • Variables cannot be defined in a compound statement unless it is the body of a function • PHP has typical scripting language characteristics – – – – Dynamic typing, un-typed variables Associative arrays Pattern matching Extensive libraries • Primitives, Operations, Expressions – Four scalar types: boolean, integer, double, string – Two compound types: array, object – Two special types: resource and NULL
  • 10. • A PHP scripting block always starts with <?php and ends with ?> <?php ……………. ?> – Other options are: 1. <? ……………… ?> 2. <script> ... </script> • There are three basic statements to output text with PHP: echo, print, and printf. Example: echo 'This is a <b>test</b>!'; • Comments: – # – // – /* . . . */
  • 11. Basic PHP Syntax  Inserting external files:  PHP provides four functions that enable you to insert code from external files: include() or require() include_once() or require_once() functions. • E.g.  include("table2.php"); – Included files start in copy mode
  • 12. Example 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Simple PHP Example</title> <body> <?php echo "Hello Class of 2011. This is my first PHP Script"; echo "<br />"; print "<b><i>What have you learnt and how many friends have you made?</i></b>"; echo "<br /><a href='PHP I-BSIC.ppt'>PHP BASIC</a>"; ?> </body> </html>
  • 13. PHP Variables • Variables are used for storing values, such as numbers, strings or function results, so that they can be used many times in a script. • All variables in PHP start with a $ sign symbol. • Variables are assigned using the assignment operator "=" • Variable names are case sensitive in PHP: $name is not the same as $NAME or $Name. • In PHP a variable does not need to be declared before being set. • PHP is a Loosely Typed Language.
  • 14. Strings in PHP • • • a string is a sequence of letters, symbols, characters and arithmetic values or combination of all tied together in single or double quotes. String literals are enclosed in single or double quotes Example: <?php $sum = 20; echo 'the sum is: $sum'; echo "<br />"; echo "the sum is: $sum"; echo "<br />"; echo '<input type="text" name="first_name" id="first_name">'; ?> – Double quoted strings have escape sequences (such as /n or /r) interpreted and variables interpolated (substituted) – Single quoted strings have neither escape sequence interpretation nor variable interpolation – A literal $ sign in a double quoted string must be escaped with a backslash, – Double-quoted strings can cover multiple lines
  • 15. PHP Function  In php a function is a predefined set of commands that are carried out when the function is called.  The real power of PHP comes from its functions.  PHP has more than 700 built-in or predefine functions for you to use.
  • 16. Using Built-in Function  Examples: Inserting external files:  PHP provides four functions that enable you to insert code from external files: include() or require() include_once() or require_once() functions.  A sample include file called add.php <html> <body> <?php function add( $x, $y ) { return $x + $y; } ?> <h1>Welcome to my home page</h1> <p>Some text</p> </body> </html> Using the include function <?php include('add.php'); echo add(2, 2); ?>
  • 17. PHP Functions - Adding parameters  A parameter is just like a variable.  The parameters are specified inside the parentheses. Syntax: <?php function function_name(param_1, ... , param_n) { statement_1; statement_2; ... statement_m; ?> } return return_value;
  • 18. PHP Functions - Adding parameters  Functions can also be used to return values. Example:   <html> <body>       <?php function add($x,$y) { $total = $x + $y; return $total; }   echo "1 + 16 = " . add(1,16); ?>   </body> </html>
  • 19. Control Structure  Control structures are the building blocks of any programming language. PHP provides all the control structures that you may have encountered anywhere. The syntax is the same as C or Perl.  Making computers think has always been the goal of the computer architect and the programmer. Using control structures computers can make simple decisions and when programmed cleverly they can do some complex things.
  • 20. PHP Switch Statement • If you want to select one of many blocks of code to be executed, use the Switch statement. • The switch statement is used to avoid long blocks of if..elseif..else code. Syntax switch (expression) { case label1: code to be executed if expression = label1; break; case label2: code to be executed if expression = label2; break; default: code to be executed if expression is different from both label1 and label2; }
  • 21. PHP Switch Statement               switch ($textcolor) { case "black": echo "I'm black"; break; case "blue": echo "I'm blue"; break; case "red": echo "I'm red"; break; default: // It must be something else echo "too bad!!, I'm something else"; }
  • 22. PHP Looping • Looping statements in PHP are used to execute the same block of code a specified number of times. • In PHP we have the following looping statements: – while - loops through a block of code if and as long as a specified condition is true – do...while - loops through a block of code once, and then repeats the loop as long as a special condition is true – for - loops through a block of code a specified number of times – foreach - loops through a block of code for each element in an array
  • 23. The while Statement Syntax while (condition) { // statements } Example <html> <head> <title>Let us count !!!</title></head> <body> <?php $limit = 10; echo "<h2> Let us count from 1 to $limit </h2><br />"; $count = 1; while ($count <= $limit) { echo "counting $count of $limit <br>"; $count++; } ?> </body> <html>
  • 24. The do...while Statement • The do...while statement will execute a block of code at least once - it then will repeat the loop as long as a condition is true. Syntax • do { code to be executed; } while (condition);         Example <html> <body> <?php $i=0; do { $i++; echo "The number is " . $i . "<br />"; } while ($i<5); ?> </body> </html>
  • 25. PHP Arrays  An array can store one or more values in a single variable name.  There are three different kind of arrays:  Numeric array - An array with a numeric ID key  Associative array - An array where each ID key is associated with a value  Multidimensional array - An array containing one or more arrays
  • 26. Numeric Array • A numeric array stores each element with a numeric ID key. • There are different ways to create a numeric array: Example 1 • In this example the ID key is automatically assigned: • $names = array("Peter","Quagmire","Joe"); Example 2 • In this example we assign the ID key manually: $names[0] = "Peter"; $names[1] = "Quagmire"; $names[2] = "Joe";
  • 27. Associative Arrays • Each ID key is associated with a value. • When storing data about specific named values, a numerical array is not always the best way to do it. • There are two ways of creating Associative Array: Example 1 • $ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34); Example 2 • $ages['Peter'] = "32"; $ages['Quagmire'] = "30"; $ages['Joe'] = "34";
  • 28. Multidimensional Arrays • In a multidimensional array, each element in the main array can also be an array. And each element in the sub-array can be an array, and so on. • Example 1 • with automatically assigned ID keys: $families = array ( "Griffin"=>array ( "Peter", "Lois", "Megan" ), "Quagmire"=>array ( "Glenn" ), "Brown"=>array ( "Cleveland", "Loretta", "Junior" ) );
  • 29. Multidimensional Arrays   Example 2: The array above would look like this if written to the output:    Array ( [Griffin] => Array  (  [0] => Peter  [1] => Lois  [2] => Megan  ) [Quagmire] => Array  (  [0] => Glenn  ) [Brown] => Array  (  [0] => Cleveland  [1] => Loretta  [2] => Junior )  )   • displaying a single value from the array above:  echo "Is " . $families['Griffin'][2] . " a part of the Griffin family?";