0% found this document useful (0 votes)
4 views

CourseLecture PHP Elements Creating and Utilization of Arrays

Uploaded by

jay.abaleta
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

CourseLecture PHP Elements Creating and Utilization of Arrays

Uploaded by

jay.abaleta
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Course Learning

PHP Elements, Creating and utilization of arrays


and different pre-defined array related functions
PHP Get and Post
GET method
• The GET method is used to submit the HTML form
data. This data is collected by the predefined $_GET variable
for processing.

Using GET method


•Information sent from a form with the GET method is visible
to everyone (all variable names and values are displayed in
the URL).
PHP Get Example

GET method:getMethod.php Output:


PHP Get Example

GET method:getDisplay.php Output:


PHP Get and Post
POST method
• Similar to the GET method, the POST method is also used to
submit the HTML form data. But the data submitted by this
method is collected by the predefined superglobal variable
$_POST instead of $_GET.
Using POST method
•Information sent from a form with the POST method is invisible to
others (all names/values are embedded within the body of the
HTTP request) and has no limits on the amount of information to
send.
PHP Get Example

POST method:postMethod.php Output:


<html>
<body>
<form action="postDisplay.php" method="post">
Name: <input type="text" name="name"><br>
Birthday: <input type="text" name="bday"><br>
<input type="submit">
</form>
</body>
</html>
PHP Get Example

GET method:postDisplay.php Output:


Variable types in PHP
•- Variables all store certain types of data.
• - PHP automatically picks a data variable based on the value
assigned.
• - These data types include strings, numbers, and more complex
types such as arrays.
Variable Scope
- In PHP, 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:


1. local 2. global 3. static
Variable Scope
LOCAL SCOPE
- A variable declared within a function and can only be accessed
within that function.
GLOBAL SCOPE
- A variable declared outside a function and can only be accessed
outside a function.
Static Variable
- Static variables provide a variable that isn't destroyed when a
function ends.
Example: Local Scope

Output:
Example: Global Scope

Output:
Example: Static Variable

Output:
Control Structures / Control Flow
The two broad types of control structures
1. Conditional Statements
Conditional statements are used to perform different actions based on
different conditions.
following 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
Control Structures / Control Flow
2. loops.
- A loop is a special kind of branch where one of the execution paths jumps
back to the beginning of the branch, repeating the test and possibly the body of the
loop.
The following loop types:
while - loops through a block of code as long as the specified condition is true
do...while - loops through a block of code once, and then repeats the loop as long as
the specified 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
PHP if statement
- if statement allows conditional execution of code. It is executed if
condition is true.
Syntax:
1. if(condition)
2. {
3. //code to be executed
4. }
EXAMPLE:

Output: 25 is greater than 20


PHP if else statement
- if-else statement is executed whether condition is true or false .
Syntax:
if (condition)
code to be executed if condition is true;
else
code to be executed if condition is false;
EXAMPLE:

Output: Welcome to the admin page.


PHP if-else-if statement
- Aspecial statement used to combine multiple if? .else statements.
- Syntax: EXAMPLE:
if (condition)
code to be executed if condition is true;
elseif (condition)
code to be executed if condition is true;
else
code to be executed if condition is false;

Output: Welcome to the Guest page.


PHP Switch statement
• It is used to perform different actions based on different conditions.
• The switch statement compares an expression to numerous values.
Syntax:
switch(expression)
{
case value1:
//code to be executed
break;
case value2:
//code to be executed
break;
......
default:
code to be executed if all cases are not matched;
}
Example:

Output:
End of Presentation

You might also like