SlideShare a Scribd company logo
1 of 61
12-Apr-19
12-Apr-19
PHP:PHP: Hypertext Preprocessor
Introduction
Syntax and Comments
Case Sensitivity
Variables
Data Types
Strings and Constants
Operators
Control Flow Statements
Functions
Arrays
Forms
PHP Introduction
PHP: Hypertext Preprocessor"
Widely Used and Open Source
Scripts Executed on Server Side-Wamp Server
Wamp --- Wamp - Windows(W), Apache (A), MySQL/MariaDB(M),
PHP (P) and Perl (P).
Free to download and Use
PHP File-Text, CSS, HTML, Java Script and a PHP code
Saved with an extension .php
Generate dynamic page content
Create, open, read, write, delete, and close files on the
server
Collect form data and Encrypt data
Add, delete, modify data in your database
PHP Syntax
A PHP script can be placed anywhere in the document.
A PHP script starts with <?php and ends with ?>:
<?php
// PHP code goes here
?>
<?php
echo "Hello World!";
?>
PHP Syntax
A PHP file normally contains HTML tags, and some PHP scripting
code.
Example
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello World!";
?>
</body>
</html>
PHP Comments
Comment Line --- not read/executed as part of the program.
Example
<html>
<body>
<?php
// This is a single-line comment
# This is also a single-line comment
/*
This is a multiple-lines comment block
that spans over multiple lines
*/
// You can also use comments to leave out parts of a code line
$x = 5 /* + 15 */ + 5; echo $x;
?>
</body>
</html>
PHP Case Sensitivity
 All Keywords are not case sensitive.
Example:
<?php
ECHO “Hello World!<br>”;
echo “Hello World!<br>”;
EcHo “Hello World!<br>”;
?>
All variable names are case sensitive.
<?php
$color=“red”;
echo “My car is “.$color. ”<br>”;
echo “My car is “.$COLOR. ”<br>”;
echo “My car is “.$CoLor. ”<br>”;
?>
PHP Variables
 Containers for storing information.
Starts with the $ sign, followed by the name of the variable.
Variable name must start with a letter or the underscore character.
Cannot start with a number.
Only contain alpha-numeric characters and underscores
(A-z, 0-9, and _ ).
Case-sensitive ($age and $AGE are two different variables).
Example
<?php
$x = 5;
$y = 4;
echo $x + $y;
?>
PHP Variables
 Variables can be declared anywhere in the script.
The scope of a variable is the part of the script where the variable
can be referenced/used.
PHP has three different variable scopes:
Local
Global
Static
PHP Variables
Local --- Declared and Accessed only within a function.
Example
<?php
function myTest() {
$x = 5; // local scope
echo "<p>Variable x inside function is: $x</p>";
}
myTest();
// using x outside the function will generate an error
echo "<p>Variable x outside function is: $x</p>";
?>
Output:
Variable x inside function is: 5
Variable x outside function is:
PHP Variables
Global --- Declared and Accessed only outside a function.
Example
<?php
$x = 5; // global scope
function myTest() {
// using x inside this function will generate an error
echo "<p>Variable x inside function is: $x</p>";
}
myTest();
echo "<p>Variable x outside function is: $x</p>";
?>
Output:
Variable x inside function is:
Variable x outside function is:5
PHP Data Types
PHP supports the following data types:
String
Integer
Float (floating point numbers - also called double)
Boolean
Array
Object
NULL
Resource
PHP Data Types
String
 Sequence of characters, like "Hello world!".
 Any text inside quotes. You can use single or double quotes:
Example
<?php
$x = "Hello world!";
$y = 'Hello world!';
echo $x;
echo "<br>";
echo $y;
?>
Output:
Hello world!
Hello world!
PHP Data Types
Integer
An integer must have at least one digit
An integer must not have a decimal point
An integer can be either positive or negative
Integers can be specified in three formats: decimal (10-based), hexadecimal
(16-based - prefixed with 0x) or octal (8-based - prefixed with 0)
Example
<?php
$x = 5985;
var_dump($x);
?>
Output:
int(5985)
PHP Data Types
Float
A number with a decimal point or a number in exponential form.
Example
<?php
$x = 59.85;
var_dump($x);
?>
Output:
float(59.85)
PHP Data Types
Boolean
A Boolean represents two possible states: TRUE or FALSE.
Used in conditional Testing.
$x = true;
$y = false;
Array
Stores multiple values in one single variable.
Example
<?php
$cars = array("Volvo","BMW","Toyota");
var_dump($cars);
?>
Output:
array(3) { [0]=> string(5) "Volvo" [1]=> string(3) "BMW" [2]=> string(6) "Toyota" }
PHP Data Types
Object
Stores data and information.
An object must be explicitly declared.
Example
<?php
class Car {
function Car() {
$this->model = "VW";
}}
$herbie = new Car(); // create an object
echo $herbie->model; // show object properties
?>
Output:
VW
PHP Data Types
Null
Special data type which can have only one value: NULL.
A variable of data type NULL -- no value assigned to it.
Variable without a value -- Automatically assigned a NULL value.
Variables can also be emptied by setting the value to NULL:
Example
<?php
$x = "Hello world!";
$x = null;
var_dump($x);
?>
Output:NULL
Resource
Storing of a reference to functions and resources external to PHP.
Advanced Data Type.
Example: Database Call.
PHP Strings
Sequence of characters, like "Hello world!".
String Functions
Example
<?php
echo strlen("Hello world!"); // outputs 12
echo str_word_count("Hello world!"); // outputs 2
echo strrev("Hello world!"); // outputs !dlrow olleH
echo strpos("Hello world!", "world"); // outputs 6
echo str_replace("world", "Dolly", "Hello world!"); // outputs Hello Dolly!
?>
PHP Constants
Like variables
Cannot be changed during the script
Starts with a letter or underscore (no $ sign before the constant name)
Automatically global across the entire script.
Example
<?php
define("GREETING", "Welcome to W3Schools.com!");
echo GREETING;
?>
Output:
Welcome to W3Schools.com!
PHP Operators
Perform operations on variables and values.
Types
Arithmetic operators
Assignment operators
Comparison operators
Increment/Decrement operators
Logical operators
String operators
Array operators
PHP Operators
Arithmetic operators
$x=20;$y=10;$m=3;$n=2;
+ ------- $x + $y ----- 30
- ------- $x - $y ----- 10
* ------- $x *$y ----- 200
/ ------- $x / $y ----- 2
% ------- $x % $y ----- 0
** ------- $m**$n ---- 9
PHP Operators
Assignment operators
x = y x = y
x += y x = x + y
x -= y x = x - y
x *= y x = x * y
x /= y x = x / y
x %= y x = x % y
PHP Operators
Comparison operators
$x=20 $y=10 $z=10
== $x == $y False
=== Identical $x === $y False
!= $x != $y True
<> $x <> $y True
!== Not Identical $x !== $y True
> $x > $y True
< $x < $y False
>= $x >= $y True
<= $x <= $y False
PHP Operators
Increment/Decrement operators
++$x Increments $x by one, then returns $x
<?php
$x = 10;
echo ++$x;
?>
Output: 11
$x++ Returns $x, then increments $x by one
<?php
$x = 10;
echo $x++;
?>
Output: 10
PHP Operators
Increment/Decrement operators
--$x Decrements $x by one, then returns $x
<?php
$x = 10;
echo --$x;
?>
Output: 9
$x-- Returns $x, then decrements $x by one
<?php
$x = 10;
echo $x--;
?>
Output: 10
PHP Operators
Logical operators
and $x and $y
or $x or $y
xor $x xor $y
&& $x && $y
|| $x || $y
! !$x
PHP Operators
String operators
. Concatenation $txt1 .txt2
<?php
$txt1 = "Hello";
$txt2 = " world!";
echo $txt1 . $txt2;
?>
Output:
Hello world!
PHP Operators
String operators
.= Concatenation assignment $txt1 .=$txt2
<?php
$txt1 = "Hello";
$txt2 = " world!";
$txt1 .= $txt2;
echo $txt1;
?>
Output:
Hello world!
PHP Operators
String operators
.= Concatenation assignment $txt1 .=$txt2
<?php
$txt1 = "Hello";
$txt2 = " world!";
$txt1 .= $txt2;
echo $txt1;
?>
Output:
Hello world!
PHP Operators
Array operators
+ Union $x + $y
<?php
$x = array("a" => "red", "b" => "green");
$y = array("c" => "blue", "d" => "yellow");
print_r($x + $y); // union of $x and $y
?>
Output:
Array ( [a] => red [b] => green [c] => blue [d] =>
yellow )
PHP Operators
Array operators
== Equality $x == $y
<?php
$x = array("a" => "red", "b" => "green");
$y = array("c" => "blue", "d" => "yellow");
var_dump($x == $y);
?>
Output:
bool(false)
PHP Operators
Array operators
=== Identity $x === $y
<?php
$x = array("a" => "red", "b" => "green");
$y = array("c" => "blue", "d" => "yellow");
var_dump($x === $y);
?>
Output:
bool(false)
PHP Operators
Array operators
!= Inequality $x != $y
<?php
$x = array("a" => "red", "b" => "green");
$y = array("c" => "blue", "d" => "yellow");
var_dump($x != $y);
?>
Output:
bool(true)
PHP Operators
Array operators
<> Inequality $x <> $y
<?php
$x = array("a" => "red", "b" => "green");
$y = array("c" => "blue", "d" => "yellow");
var_dump($x <> $y);
?>
Output:
bool(true)
PHP Operators
Array operators
!== Non-identity $x !== $y
<?php
$x = array("a" => "red", "b" => "green");
$y = array("c" => "blue", "d" => "yellow");
var_dump($x !== $y);
?>
Output:
bool(true)
PHP Control Flow Statements
PHP Conditional Statements
•if statement - executes some code if one condition is
true
•if...else statement - executes some code if a condition is
true and another code if that condition is false
•if...elseif....else statement - executes different codes for
more than two conditions
•switch statement - selects one of many blocks of code to
be executed
PHP Control Flow Statements
PHP Conditional Statements
•if statement - executes some code if one condition is
true
Syntax
if (condition) {
code to be executed if condition is true;
}
Example
<?php
$t = 15;
if ($t < 20) {
echo "Have a good day!";
}?>
Output:
Have a good day!
PHP Control Flow Statements
•if...else statement
Syntax:
if (condition) {
code to be executed if condition is true;
} else {
code to be executed if condition is false;
}
Example
<?php
$t = 25;
if ($t < 20 {
echo "Have a good day!";
} else {
echo "Have a good night!";
}?>
Output:
Have a good night!
PHP Control Flow Statements
•if...elseif....else statement
Syntax:
if (condition)
{
code to be executed if this condition is true;
}
elseif (condition)
{
code to be executed if this condition is true;
}
else
{
code to be executed if all conditions are false;
}
PHP Control Flow Statements
•Example
<?php
$a=20;$b=200;
if ($a > $b) {
echo "a is bigger than b";
} elseif ($a == $b) {
echo "a is equal to b";
} else {
echo "a is smaller than b";
}
?>
Output:
a is smaller than b
PHP Control Flow Statements
•Switch statement
Syntax:
switch (n) {
case label1:
code to be executed if n=label1;
break;
case label2:
code to be executed if n=label2;
break;
case label3:
code to be executed if n=label3;
break;
...
default:
code to be executed if n is different from all labels;
}
PHP Control Flow Statements
•Switch statement
Example:
<?php
$favcolor = "red";
switch ($favcolor) {
case "red":
echo "Your favorite color is red!";
break;
case "blue":
echo "Your favorite color is blue!";
break;
default:
echo "Your favorite color is neither red, blue, nor green!";
}?>
Output:
Your favorite color is red!
PHP Control Flow Statements
•While statement
while - loops through a block of code as long as the specified
condition is true
Syntax
while (condition is true) {
code to be executed;}
Example
<?php
$x = 1;
while($x <= 3) {
echo "The number is: $x <br>";
$x++;
}?>
Output:
The number is: 1 The number is: 2 The number is: 3
PHP Control Flow Statements
•Do…While statement
Do…while -loops through a block of code once, and then
repeats the loop as long as the specified condition is true
Syntax
do {
code to be executed;
} while (condition is true);
Example
<?php
$x = 1;
do {
echo "The number is: $x <br>";
$x++;
} while ($x >= 5);
?>
Output:
The number is: 1
PHP Control Flow Statements
•For loop statement
for - loops through a block of code a specified number of
times
Syntax
for (init counter; test counter; increment counter) {
code to be executed; }
Example
<?php
for ($x = 0; $x <= 2; $x++) {
echo "The number is: $x <br>";
}
?>
Output:
The number is: 0
The number is: 1
The number is: 2
PHP Control Flow Statements
•For loop statement
For each - loops through a block of code for each element
in an array and it works on arrays.
Syntax
for each ($array as $value) {
code to be executed; }
Example
<?php
$colors = array("red", "green", "blue", "yellow");
foreach ($colors as $value) {
echo "$value <br>“; } ?>
Output:
red
green
blue
yellow
PHP Functions
Functions
•Block of statements that can be used repeatedly in a
program.
•Not execute immediately when a page loads.
•Executed by a call to the function.
Syntax
function functionName() {
code to be executed;
}
Example:
<?php
function writeMsg() {
echo "Hello world!“; }
writeMsg(); // call the function
?>
PHP Functions
Example:
<?php
function familyName($fname, $year) {
echo "$fname Refsnes. Born in $year <br>";
}
familyName("Hege", "1975");
?>
Example:
<?php
function setHeight($minheight = 50) {
echo "The height is : $minheight <br>";
}
setHeight(350);
setHeight(); // will use the default value of 50
PHP Functions
Example:
<?php
function sum($x, $y) {
$z = $x + $y;
return $z;
}
echo "5 + 10 = " . sum(5, 10) . "<br>";
echo "7 + 13 = " . sum(7, 13) . "<br>";
echo "2 + 4 = " . sum(2, 4);
?>
PHP Arrays
An array is a special variable, which can hold more than one value
at a time.
Types:
Indexed arrays - Arrays with a numeric index
Associative arrays - Arrays with named keys
Multidimensional arrays - Containing one or more arrays
Example
<?php
$cars = array("Volvo", "BMW”);
echo "I like " . $cars[0] . ”and " . $cars[1] . ".";
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
echo "Peter is " . $age['Peter'] . " years old.";
?>
Output:
I like Volvo and BMW.
Peter is 35 years old.
PHP - A Simple HTML Form
Example
<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
PHP - A Simple HTML Form
PHP - A Simple HTML Form
Example
Welcome.php
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
PHP - A Simple HTML Form
PHP - A Simple HTML Form
Example
welget.html
<html>
<body>
<form action="welget.php" method="get">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
PHP - A Simple HTML Form
PHP - A Simple HTML Form
Example
welget.php
<html>
<body>
Welcome <?php echo $_GET["name"]; ?><br>
Your email address is: <?php echo $_GET["email"]; ?>
</body>
</html>
PHP - A Simple HTML Form
PHP Basics

More Related Content

What's hot

2014 database - course 2 - php
2014 database - course 2 - php2014 database - course 2 - php
2014 database - course 2 - phpHung-yu Lin
 
PHP「参照渡しできるよ」(君の考えている参照渡しと同じとは言ってない)
PHP「参照渡しできるよ」(君の考えている参照渡しと同じとは言ってない)PHP「参照渡しできるよ」(君の考えている参照渡しと同じとは言ってない)
PHP「参照渡しできるよ」(君の考えている参照渡しと同じとは言ってない)Kana Natsuno
 
Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHPAhmed Swilam
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboardsDenis Ristic
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Muhamad Al Imran
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Muhamad Al Imran
 
Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Nikita Popov
 
[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?Radek Benkel
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP FunctionsAhmed Swilam
 

What's hot (20)

Basic PHP
Basic PHPBasic PHP
Basic PHP
 
Php introduction
Php introductionPhp introduction
Php introduction
 
2014 database - course 2 - php
2014 database - course 2 - php2014 database - course 2 - php
2014 database - course 2 - php
 
PHP「参照渡しできるよ」(君の考えている参照渡しと同じとは言ってない)
PHP「参照渡しできるよ」(君の考えている参照渡しと同じとは言ってない)PHP「参照渡しできるよ」(君の考えている参照渡しと同じとは言ってない)
PHP「参照渡しできるよ」(君の考えている参照渡しと同じとは言ってない)
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHP
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
 
Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8
 
Sorting arrays in PHP
Sorting arrays in PHPSorting arrays in PHP
Sorting arrays in PHP
 
slidesharenew1
slidesharenew1slidesharenew1
slidesharenew1
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!
 
SPL, not a bridge too far
SPL, not a bridge too farSPL, not a bridge too far
SPL, not a bridge too far
 
Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
 
[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?
 
PHP POWERPOINT SLIDES
PHP POWERPOINT SLIDESPHP POWERPOINT SLIDES
PHP POWERPOINT SLIDES
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
 
Intermediate PHP
Intermediate PHPIntermediate PHP
Intermediate PHP
 

Similar to PHP Basics (20)

FYBSC IT Web Programming Unit IV PHP and MySQL
FYBSC IT Web Programming Unit IV  PHP and MySQLFYBSC IT Web Programming Unit IV  PHP and MySQL
FYBSC IT Web Programming Unit IV PHP and MySQL
 
PHP Basic
PHP BasicPHP Basic
PHP Basic
 
Php + my sql
Php + my sqlPhp + my sql
Php + my sql
 
OpenGurukul : Language : PHP
OpenGurukul : Language : PHPOpenGurukul : Language : PHP
OpenGurukul : Language : PHP
 
Php basic for vit university
Php basic for vit universityPhp basic for vit university
Php basic for vit university
 
Php
PhpPhp
Php
 
Learn PHP Basics
Learn PHP Basics Learn PHP Basics
Learn PHP Basics
 
php AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdfphp AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdf
 
Web 8 | Introduction to PHP
Web 8 | Introduction to PHPWeb 8 | Introduction to PHP
Web 8 | Introduction to PHP
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
PHP-Part1
PHP-Part1PHP-Part1
PHP-Part1
 
Giới thiệu PHP 7
Giới thiệu PHP 7Giới thiệu PHP 7
Giới thiệu PHP 7
 
Php Tutorial | Introduction Demo | Basics
 Php Tutorial | Introduction Demo | Basics Php Tutorial | Introduction Demo | Basics
Php Tutorial | Introduction Demo | Basics
 
Php My SQL Tutorial | beginning
Php My SQL Tutorial | beginningPhp My SQL Tutorial | beginning
Php My SQL Tutorial | beginning
 
Learning of Php and My SQL Tutorial | For Beginners
Learning of Php and My SQL Tutorial | For BeginnersLearning of Php and My SQL Tutorial | For Beginners
Learning of Php and My SQL Tutorial | For Beginners
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 

More from Saraswathi Murugan

More from Saraswathi Murugan (7)

Data mining in e commerce
Data mining in e commerceData mining in e commerce
Data mining in e commerce
 
Data mining
Data miningData mining
Data mining
 
Python modulesfinal
Python modulesfinalPython modulesfinal
Python modulesfinal
 
National Identity Elements of India
National Identity Elements of IndiaNational Identity Elements of India
National Identity Elements of India
 
Advanced Concepts in Python
Advanced Concepts in PythonAdvanced Concepts in Python
Advanced Concepts in Python
 
Pythonppt28 11-18
Pythonppt28 11-18Pythonppt28 11-18
Pythonppt28 11-18
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE
 

Recently uploaded

INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxnelietumpap1
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 

Recently uploaded (20)

TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 

PHP Basics

  • 3. PHP:PHP: Hypertext Preprocessor Introduction Syntax and Comments Case Sensitivity Variables Data Types Strings and Constants Operators Control Flow Statements Functions Arrays Forms
  • 4. PHP Introduction PHP: Hypertext Preprocessor" Widely Used and Open Source Scripts Executed on Server Side-Wamp Server Wamp --- Wamp - Windows(W), Apache (A), MySQL/MariaDB(M), PHP (P) and Perl (P). Free to download and Use PHP File-Text, CSS, HTML, Java Script and a PHP code Saved with an extension .php Generate dynamic page content Create, open, read, write, delete, and close files on the server Collect form data and Encrypt data Add, delete, modify data in your database
  • 5. PHP Syntax A PHP script can be placed anywhere in the document. A PHP script starts with <?php and ends with ?>: <?php // PHP code goes here ?> <?php echo "Hello World!"; ?>
  • 6. PHP Syntax A PHP file normally contains HTML tags, and some PHP scripting code. Example <!DOCTYPE html> <html> <body> <h1>My first PHP page</h1> <?php echo "Hello World!"; ?> </body> </html>
  • 7. PHP Comments Comment Line --- not read/executed as part of the program. Example <html> <body> <?php // This is a single-line comment # This is also a single-line comment /* This is a multiple-lines comment block that spans over multiple lines */ // You can also use comments to leave out parts of a code line $x = 5 /* + 15 */ + 5; echo $x; ?> </body> </html>
  • 8. PHP Case Sensitivity  All Keywords are not case sensitive. Example: <?php ECHO “Hello World!<br>”; echo “Hello World!<br>”; EcHo “Hello World!<br>”; ?> All variable names are case sensitive. <?php $color=“red”; echo “My car is “.$color. ”<br>”; echo “My car is “.$COLOR. ”<br>”; echo “My car is “.$CoLor. ”<br>”; ?>
  • 9. PHP Variables  Containers for storing information. Starts with the $ sign, followed by the name of the variable. Variable name must start with a letter or the underscore character. Cannot start with a number. Only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ). Case-sensitive ($age and $AGE are two different variables). Example <?php $x = 5; $y = 4; echo $x + $y; ?>
  • 10. PHP Variables  Variables can be declared anywhere in the script. The scope of a variable is the part of the script where the variable can be referenced/used. PHP has three different variable scopes: Local Global Static
  • 11. PHP Variables Local --- Declared and Accessed only within a function. Example <?php function myTest() { $x = 5; // local scope echo "<p>Variable x inside function is: $x</p>"; } myTest(); // using x outside the function will generate an error echo "<p>Variable x outside function is: $x</p>"; ?> Output: Variable x inside function is: 5 Variable x outside function is:
  • 12. PHP Variables Global --- Declared and Accessed only outside a function. Example <?php $x = 5; // global scope function myTest() { // using x inside this function will generate an error echo "<p>Variable x inside function is: $x</p>"; } myTest(); echo "<p>Variable x outside function is: $x</p>"; ?> Output: Variable x inside function is: Variable x outside function is:5
  • 13. PHP Data Types PHP supports the following data types: String Integer Float (floating point numbers - also called double) Boolean Array Object NULL Resource
  • 14. PHP Data Types String  Sequence of characters, like "Hello world!".  Any text inside quotes. You can use single or double quotes: Example <?php $x = "Hello world!"; $y = 'Hello world!'; echo $x; echo "<br>"; echo $y; ?> Output: Hello world! Hello world!
  • 15. PHP Data Types Integer An integer must have at least one digit An integer must not have a decimal point An integer can be either positive or negative Integers can be specified in three formats: decimal (10-based), hexadecimal (16-based - prefixed with 0x) or octal (8-based - prefixed with 0) Example <?php $x = 5985; var_dump($x); ?> Output: int(5985)
  • 16. PHP Data Types Float A number with a decimal point or a number in exponential form. Example <?php $x = 59.85; var_dump($x); ?> Output: float(59.85)
  • 17. PHP Data Types Boolean A Boolean represents two possible states: TRUE or FALSE. Used in conditional Testing. $x = true; $y = false; Array Stores multiple values in one single variable. Example <?php $cars = array("Volvo","BMW","Toyota"); var_dump($cars); ?> Output: array(3) { [0]=> string(5) "Volvo" [1]=> string(3) "BMW" [2]=> string(6) "Toyota" }
  • 18. PHP Data Types Object Stores data and information. An object must be explicitly declared. Example <?php class Car { function Car() { $this->model = "VW"; }} $herbie = new Car(); // create an object echo $herbie->model; // show object properties ?> Output: VW
  • 19. PHP Data Types Null Special data type which can have only one value: NULL. A variable of data type NULL -- no value assigned to it. Variable without a value -- Automatically assigned a NULL value. Variables can also be emptied by setting the value to NULL: Example <?php $x = "Hello world!"; $x = null; var_dump($x); ?> Output:NULL Resource Storing of a reference to functions and resources external to PHP. Advanced Data Type. Example: Database Call.
  • 20. PHP Strings Sequence of characters, like "Hello world!". String Functions Example <?php echo strlen("Hello world!"); // outputs 12 echo str_word_count("Hello world!"); // outputs 2 echo strrev("Hello world!"); // outputs !dlrow olleH echo strpos("Hello world!", "world"); // outputs 6 echo str_replace("world", "Dolly", "Hello world!"); // outputs Hello Dolly! ?>
  • 21. PHP Constants Like variables Cannot be changed during the script Starts with a letter or underscore (no $ sign before the constant name) Automatically global across the entire script. Example <?php define("GREETING", "Welcome to W3Schools.com!"); echo GREETING; ?> Output: Welcome to W3Schools.com!
  • 22. PHP Operators Perform operations on variables and values. Types Arithmetic operators Assignment operators Comparison operators Increment/Decrement operators Logical operators String operators Array operators
  • 23. PHP Operators Arithmetic operators $x=20;$y=10;$m=3;$n=2; + ------- $x + $y ----- 30 - ------- $x - $y ----- 10 * ------- $x *$y ----- 200 / ------- $x / $y ----- 2 % ------- $x % $y ----- 0 ** ------- $m**$n ---- 9
  • 24. PHP Operators Assignment operators x = y x = y x += y x = x + y x -= y x = x - y x *= y x = x * y x /= y x = x / y x %= y x = x % y
  • 25. PHP Operators Comparison operators $x=20 $y=10 $z=10 == $x == $y False === Identical $x === $y False != $x != $y True <> $x <> $y True !== Not Identical $x !== $y True > $x > $y True < $x < $y False >= $x >= $y True <= $x <= $y False
  • 26. PHP Operators Increment/Decrement operators ++$x Increments $x by one, then returns $x <?php $x = 10; echo ++$x; ?> Output: 11 $x++ Returns $x, then increments $x by one <?php $x = 10; echo $x++; ?> Output: 10
  • 27. PHP Operators Increment/Decrement operators --$x Decrements $x by one, then returns $x <?php $x = 10; echo --$x; ?> Output: 9 $x-- Returns $x, then decrements $x by one <?php $x = 10; echo $x--; ?> Output: 10
  • 28. PHP Operators Logical operators and $x and $y or $x or $y xor $x xor $y && $x && $y || $x || $y ! !$x
  • 29. PHP Operators String operators . Concatenation $txt1 .txt2 <?php $txt1 = "Hello"; $txt2 = " world!"; echo $txt1 . $txt2; ?> Output: Hello world!
  • 30. PHP Operators String operators .= Concatenation assignment $txt1 .=$txt2 <?php $txt1 = "Hello"; $txt2 = " world!"; $txt1 .= $txt2; echo $txt1; ?> Output: Hello world!
  • 31. PHP Operators String operators .= Concatenation assignment $txt1 .=$txt2 <?php $txt1 = "Hello"; $txt2 = " world!"; $txt1 .= $txt2; echo $txt1; ?> Output: Hello world!
  • 32. PHP Operators Array operators + Union $x + $y <?php $x = array("a" => "red", "b" => "green"); $y = array("c" => "blue", "d" => "yellow"); print_r($x + $y); // union of $x and $y ?> Output: Array ( [a] => red [b] => green [c] => blue [d] => yellow )
  • 33. PHP Operators Array operators == Equality $x == $y <?php $x = array("a" => "red", "b" => "green"); $y = array("c" => "blue", "d" => "yellow"); var_dump($x == $y); ?> Output: bool(false)
  • 34. PHP Operators Array operators === Identity $x === $y <?php $x = array("a" => "red", "b" => "green"); $y = array("c" => "blue", "d" => "yellow"); var_dump($x === $y); ?> Output: bool(false)
  • 35. PHP Operators Array operators != Inequality $x != $y <?php $x = array("a" => "red", "b" => "green"); $y = array("c" => "blue", "d" => "yellow"); var_dump($x != $y); ?> Output: bool(true)
  • 36. PHP Operators Array operators <> Inequality $x <> $y <?php $x = array("a" => "red", "b" => "green"); $y = array("c" => "blue", "d" => "yellow"); var_dump($x <> $y); ?> Output: bool(true)
  • 37. PHP Operators Array operators !== Non-identity $x !== $y <?php $x = array("a" => "red", "b" => "green"); $y = array("c" => "blue", "d" => "yellow"); var_dump($x !== $y); ?> Output: bool(true)
  • 38. PHP Control Flow Statements PHP Conditional Statements •if statement - executes some code if one condition is true •if...else statement - executes some code if a condition is true and another code if that condition is false •if...elseif....else statement - executes different codes for more than two conditions •switch statement - selects one of many blocks of code to be executed
  • 39. PHP Control Flow Statements PHP Conditional Statements •if statement - executes some code if one condition is true Syntax if (condition) { code to be executed if condition is true; } Example <?php $t = 15; if ($t < 20) { echo "Have a good day!"; }?> Output: Have a good day!
  • 40. PHP Control Flow Statements •if...else statement Syntax: if (condition) { code to be executed if condition is true; } else { code to be executed if condition is false; } Example <?php $t = 25; if ($t < 20 { echo "Have a good day!"; } else { echo "Have a good night!"; }?> Output: Have a good night!
  • 41. PHP Control Flow Statements •if...elseif....else statement Syntax: if (condition) { code to be executed if this condition is true; } elseif (condition) { code to be executed if this condition is true; } else { code to be executed if all conditions are false; }
  • 42. PHP Control Flow Statements •Example <?php $a=20;$b=200; if ($a > $b) { echo "a is bigger than b"; } elseif ($a == $b) { echo "a is equal to b"; } else { echo "a is smaller than b"; } ?> Output: a is smaller than b
  • 43. PHP Control Flow Statements •Switch statement Syntax: switch (n) { case label1: code to be executed if n=label1; break; case label2: code to be executed if n=label2; break; case label3: code to be executed if n=label3; break; ... default: code to be executed if n is different from all labels; }
  • 44. PHP Control Flow Statements •Switch statement Example: <?php $favcolor = "red"; switch ($favcolor) { case "red": echo "Your favorite color is red!"; break; case "blue": echo "Your favorite color is blue!"; break; default: echo "Your favorite color is neither red, blue, nor green!"; }?> Output: Your favorite color is red!
  • 45. PHP Control Flow Statements •While statement while - loops through a block of code as long as the specified condition is true Syntax while (condition is true) { code to be executed;} Example <?php $x = 1; while($x <= 3) { echo "The number is: $x <br>"; $x++; }?> Output: The number is: 1 The number is: 2 The number is: 3
  • 46. PHP Control Flow Statements •Do…While statement Do…while -loops through a block of code once, and then repeats the loop as long as the specified condition is true Syntax do { code to be executed; } while (condition is true); Example <?php $x = 1; do { echo "The number is: $x <br>"; $x++; } while ($x >= 5); ?> Output: The number is: 1
  • 47. PHP Control Flow Statements •For loop statement for - loops through a block of code a specified number of times Syntax for (init counter; test counter; increment counter) { code to be executed; } Example <?php for ($x = 0; $x <= 2; $x++) { echo "The number is: $x <br>"; } ?> Output: The number is: 0 The number is: 1 The number is: 2
  • 48. PHP Control Flow Statements •For loop statement For each - loops through a block of code for each element in an array and it works on arrays. Syntax for each ($array as $value) { code to be executed; } Example <?php $colors = array("red", "green", "blue", "yellow"); foreach ($colors as $value) { echo "$value <br>“; } ?> Output: red green blue yellow
  • 49. PHP Functions Functions •Block of statements that can be used repeatedly in a program. •Not execute immediately when a page loads. •Executed by a call to the function. Syntax function functionName() { code to be executed; } Example: <?php function writeMsg() { echo "Hello world!“; } writeMsg(); // call the function ?>
  • 50. PHP Functions Example: <?php function familyName($fname, $year) { echo "$fname Refsnes. Born in $year <br>"; } familyName("Hege", "1975"); ?> Example: <?php function setHeight($minheight = 50) { echo "The height is : $minheight <br>"; } setHeight(350); setHeight(); // will use the default value of 50
  • 51. PHP Functions Example: <?php function sum($x, $y) { $z = $x + $y; return $z; } echo "5 + 10 = " . sum(5, 10) . "<br>"; echo "7 + 13 = " . sum(7, 13) . "<br>"; echo "2 + 4 = " . sum(2, 4); ?>
  • 52. PHP Arrays An array is a special variable, which can hold more than one value at a time. Types: Indexed arrays - Arrays with a numeric index Associative arrays - Arrays with named keys Multidimensional arrays - Containing one or more arrays Example <?php $cars = array("Volvo", "BMW”); echo "I like " . $cars[0] . ”and " . $cars[1] . "."; $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43"); echo "Peter is " . $age['Peter'] . " years old."; ?> Output: I like Volvo and BMW. Peter is 35 years old.
  • 53. PHP - A Simple HTML Form Example <html> <body> <form action="welcome.php" method="post"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name="email"><br> <input type="submit"> </form> </body> </html>
  • 54. PHP - A Simple HTML Form
  • 55. PHP - A Simple HTML Form Example Welcome.php <html> <body> Welcome <?php echo $_POST["name"]; ?><br> Your email address is: <?php echo $_POST["email"]; ?> </body> </html>
  • 56. PHP - A Simple HTML Form
  • 57. PHP - A Simple HTML Form Example welget.html <html> <body> <form action="welget.php" method="get"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name="email"><br> <input type="submit"> </form> </body> </html>
  • 58. PHP - A Simple HTML Form
  • 59. PHP - A Simple HTML Form Example welget.php <html> <body> Welcome <?php echo $_GET["name"]; ?><br> Your email address is: <?php echo $_GET["email"]; ?> </body> </html>
  • 60. PHP - A Simple HTML Form