SlideShare ist ein Scribd-Unternehmen logo
1 von 37
PHP Course
2: Conditional Statements
PHP Course

Info@ITBigDig.com
Instructor
 Name: Mohamed Saad.
 Email: Engsaad_aly@hotmail.com
 Occupation: Web Developer In IT Big Dig.
PHP Course

Info@ITBigDig.com
Contents
• PHP Array
o Introduction.

• Conditional Statements.
o if statement.
o if...else statement.
o if...else if....else statement.
o switch statement.

PHP Course

Info@ITBigDig.com
PHP Array
• There are three types of arrays:
Indexed arrays

•Arrays with numeric index

Associative arrays

• Arrays with named keys

Multidimensional
arrays

•Arrays containing one or more arrays
Array Function
Syntax

indexed
associative

•array(‘value’, );
•array(‘key’ =>’value’, );
<pre>
<?php
$x = array ('saad','nacer city','zkzk@hotmail');
print_r ($x);

Copy Code
outputdata.php

$y = array ('name' => 'saad', 'address' => 'nacer city', 'email' =>
array ('zkzk@hotmail', 'zkzk@yahoo', 'zkzk@gmail'));
print_r ($y);
?>
</pre>

PHP Course

Info@ITBigDig.com
Conditional Statements
1) if statement - executes some code only if a specified

condition is true.
2) if...else statement - executes some code if a condition is
true and another code if the condition is false.

3) if...else if....else statement - selects one of several blocks
of code to be executed.
4) switch statement - selects one or more of many blocks

of code to be executed.
if statement
Syntax
o if (condition)
{
code to be executed if condition is true;
}

PHP Course

Info@ITBigDig.com
Example: if statement
HTML

PHP

Dig: Check value entered by user.
<html>
<body>

Copy Code
game.php

<form action="game.php" method="post">
Enter number between 1 and 100:<input type="text" name="x"/>
<input type="submit" name="submit" value="xxx"/>
</form>
</body>
</html>
<?php
if (empty($_POST)===false)
{
$x=$_POST['x'];
if($x>50)
{
echo 'U Entered Number ',$x,' greater than 50','<br>';
echo 'U Entered Number '.$x.' greater than 50';
exit();
}
}
?>

PHP Course

Info@ITBigDig.com
Getdate Function
Syntax
<?php

timestamp

print_r(getdate( ));

?>
o getdate(timestamp);
• Timestamp
o Default (time())
o “U” Specifies an integer Unix timestamp
Key
"seconds"
"minutes"
"hours"
"mday"
"wday"
"mon"

Returned Values
0 to 59
0 to 59
0 to 23
1 to 31
0 (for Sunday)
1 through 12

"year"

Examples: 1970 or 2011

"yday"

0 through 365

"weekday"

Sunday through Saturday

"month"

January through December

0

Unix Epoch: is a system for describing points in time
-2147483648 through 2147483647.
<pre>
Copy Code
<?php
Conditional_statement.php
print_r(getdate());
echo '<br/>';
$mydate=getdate(date(time()));
echo"--------------------------------------------";
echo"<br/>";
echo "date: $mydate[weekday], $mydate[month] $mydate[mday],
$mydate[year]";
echo"<br/>";
echo "time: H:$mydate[hours], M:$mydate[minutes],
S:$mydate[seconds]";
echo"<br/>";
if ($mydate[“mday”]>=20)
{
echo"--------------------------------------------";
echo"<br/>";
echo "we are at the end of the month";
}
?>
</pre>

PHP Course

Info@ITBigDig.com
localtime Function
Syntax
<?php
print_r(localtime());

?>
Is Associative
Is Associative
• If set to FALSE or not supplied then the array is
returned as a regular, numerically indexed array. If
the argument is set to TRUE then localtime() returns
an associative array containing all the different
elements of the structure returned by the C function

call to localtime.
if...else Statement
Syntax
if (condition)
{
code to be executed if condition is true;
}
else
{
code to be executed if condition is false;
}

PHP Course

Info@ITBigDig.com
<?php

Copy PHP Code

if (empty($_POST)===false)
{
$x=$_POST['x'];
if ($x>50){
echo 'U Entered Number ',$x,' greater than 50','<br>';
exit();
}
else
{
echo 'U Entered Number ',$x,' less than 50','<br>';
exit();
}
}

?>
if...else if....else Statement
Syntax
if (condition) {
} else if (condition) {
} elss {
}
<html>
Copy Code
<body>
game.php
<form action="game.php" method="post">
Enter number between 1 and 100:<input type="text" name="x"/>
<input type="submit" name="submit" value="Go"/>
</form>
</body>
</html>
<?php
if (empty($_POST)===false)
{
$x=$_POST['x'];
if($x>50){
echo 'U Entered Number ',$x,' greater than 50','<br>';
exit();
}else if($x<50){
echo 'U Entered Number ',$x,' less than 50','<br>';
exit();
}else
{
echo 'U Entered Number ',$x;
exit();
}
}
?>
I think it`s clear now…!

PHP Course

Info@ITBigDig.com
Date Function

Syntax
<?php

echo date("H:i:s");
?>

H

24-hour format

00 through 23
Switch statement
Syntax
o switch (n)
{
case label1:
code to be executed if n=label1;
break;
case label2:
code to be executed if n=label2;
break;
default:
code to be executed if n is different from both
label1 and label2;
}
Switch statement
Power Syntax
o switch (variable)
{
case (condition):
code to be executed if condition is true;
break;
case (condition):
code to be executed if condition is true;
break;
default:
All conditions are false;
}
<?php
$x="red";
switch ($x)
{
case "blue":
echo "Your favorite color is blue!";
break;
case "red":
echo "___________________<br>";
echo "Your favorite color is red!";
break;
case "green":
echo "Your favorite color is green!";
break;
default:
echo "no matching color!";
}

Copy Code
switch2.php

?>
PHP Course

Info@ITBigDig.com
H

24-hour format

00 through 23
<?php

Copy Code
switch.php

$hours = date("H");
$hours=$hours-2;
echo $hours,date(":i:s");
echo "<br/>";
?>
<?php
switch ($hours)
{
case ($hours>5 and $hours<6):
echo "it is the time of the TV News <br/>";
case ($hours>=6 and $hours<8):
echo "Read something<br/>";
case ($hours>=8 and $hours<10):
echo "PlayStation time<br/>";
default:
echo "GoodNight";
}
?>

PHP Course

Info@ITBigDig.com
Character

Description

Expected O/P

d

Day of the month,

j

Day of the month without leading
zeros

D
l

A textual representation
of a day

2 digits

Returned Values
01 to 31
1 to 31

Three letters Mon through Sun

A full textual representation of the day Sunday through
of the week it is lowercase “L”
Saturday

N

ISO-8601 numeric
representation of the day
of the week (PHP 5.1.0)

S

English ordinal suffix for
the day of the month,

z

The day of the year

1 digit

1 (for Monday)
through 7 (for
Sunday)

2 characters st, nd, rd or th.
0 through 365
For complete reference Go To
http://php.net/manual/en/function.date.
php
PHP Course

Info@ITBigDig.com
End
Conditional Statements
We hope You enjoy This Tutorial.
For any Suggestions Please Email Us
Info@ITBigDig.com

PHP Course

Info@ITBigDig.com

Weitere ähnliche Inhalte

Was ist angesagt?

Everything I always wanted to know about crypto, but never thought I'd unders...
Everything I always wanted to know about crypto, but never thought I'd unders...Everything I always wanted to know about crypto, but never thought I'd unders...
Everything I always wanted to know about crypto, but never thought I'd unders...Codemotion
 
Network security
Network securityNetwork security
Network securitybabyangle
 
Fundamentals of Cryptography - Caesar Cipher - Python
Fundamentals of Cryptography - Caesar Cipher - Python Fundamentals of Cryptography - Caesar Cipher - Python
Fundamentals of Cryptography - Caesar Cipher - Python Isham Rashik
 
Dns server clients (actual program)
Dns server clients (actual program)Dns server clients (actual program)
Dns server clients (actual program)Youssef Dirani
 
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...MongoDB
 
Creating Domain Specific Languages in Python
Creating Domain Specific Languages in PythonCreating Domain Specific Languages in Python
Creating Domain Specific Languages in PythonSiddhi
 
Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! aleks-f
 
Erlang for data ops
Erlang for data opsErlang for data ops
Erlang for data opsmnacos
 
MongoDB Europe 2016 - Enabling the Internet of Things at Proximus - Belgium's...
MongoDB Europe 2016 - Enabling the Internet of Things at Proximus - Belgium's...MongoDB Europe 2016 - Enabling the Internet of Things at Proximus - Belgium's...
MongoDB Europe 2016 - Enabling the Internet of Things at Proximus - Belgium's...MongoDB
 
Pim Elshoff "Technically DDD"
Pim Elshoff "Technically DDD"Pim Elshoff "Technically DDD"
Pim Elshoff "Technically DDD"Fwdays
 
Programming - Marla Fuentes
Programming - Marla FuentesProgramming - Marla Fuentes
Programming - Marla Fuentesmfuentessss
 
Fnt Software Solutions Pvt Ltd Placement Papers - PHP Technology
Fnt Software Solutions Pvt Ltd Placement Papers - PHP TechnologyFnt Software Solutions Pvt Ltd Placement Papers - PHP Technology
Fnt Software Solutions Pvt Ltd Placement Papers - PHP Technologyfntsofttech
 
Encrypt all transports
Encrypt all transportsEncrypt all transports
Encrypt all transportsEleanor McHugh
 
How to leverage what's new in MongoDB 3.6
How to leverage what's new in MongoDB 3.6How to leverage what's new in MongoDB 3.6
How to leverage what's new in MongoDB 3.6Maxime Beugnet
 
Fantastic DSL in Python
Fantastic DSL in PythonFantastic DSL in Python
Fantastic DSL in Pythonkwatch
 

Was ist angesagt? (20)

Binomial heap
Binomial heapBinomial heap
Binomial heap
 
Everything I always wanted to know about crypto, but never thought I'd unders...
Everything I always wanted to know about crypto, but never thought I'd unders...Everything I always wanted to know about crypto, but never thought I'd unders...
Everything I always wanted to know about crypto, but never thought I'd unders...
 
Network security
Network securityNetwork security
Network security
 
Fundamentals of Cryptography - Caesar Cipher - Python
Fundamentals of Cryptography - Caesar Cipher - Python Fundamentals of Cryptography - Caesar Cipher - Python
Fundamentals of Cryptography - Caesar Cipher - Python
 
Ip project
Ip projectIp project
Ip project
 
Dns server clients (actual program)
Dns server clients (actual program)Dns server clients (actual program)
Dns server clients (actual program)
 
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
 
Creating Domain Specific Languages in Python
Creating Domain Specific Languages in PythonCreating Domain Specific Languages in Python
Creating Domain Specific Languages in Python
 
Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! 
 
Erlang for data ops
Erlang for data opsErlang for data ops
Erlang for data ops
 
Whispered secrets
Whispered secretsWhispered secrets
Whispered secrets
 
MongoDB Europe 2016 - Enabling the Internet of Things at Proximus - Belgium's...
MongoDB Europe 2016 - Enabling the Internet of Things at Proximus - Belgium's...MongoDB Europe 2016 - Enabling the Internet of Things at Proximus - Belgium's...
MongoDB Europe 2016 - Enabling the Internet of Things at Proximus - Belgium's...
 
Pim Elshoff "Technically DDD"
Pim Elshoff "Technically DDD"Pim Elshoff "Technically DDD"
Pim Elshoff "Technically DDD"
 
Programming - Marla Fuentes
Programming - Marla FuentesProgramming - Marla Fuentes
Programming - Marla Fuentes
 
Fnt Software Solutions Pvt Ltd Placement Papers - PHP Technology
Fnt Software Solutions Pvt Ltd Placement Papers - PHP TechnologyFnt Software Solutions Pvt Ltd Placement Papers - PHP Technology
Fnt Software Solutions Pvt Ltd Placement Papers - PHP Technology
 
Useful c programs
Useful c programsUseful c programs
Useful c programs
 
Encrypt all transports
Encrypt all transportsEncrypt all transports
Encrypt all transports
 
How to leverage what's new in MongoDB 3.6
How to leverage what's new in MongoDB 3.6How to leverage what's new in MongoDB 3.6
How to leverage what's new in MongoDB 3.6
 
Fantastic DSL in Python
Fantastic DSL in PythonFantastic DSL in Python
Fantastic DSL in Python
 
C# - What's next
C# - What's nextC# - What's next
C# - What's next
 

Ähnlich wie Conditional Statementfinal PHP 02

Ähnlich wie Conditional Statementfinal PHP 02 (20)

PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
Php(report)
Php(report)Php(report)
Php(report)
 
PHP Static Code Review
PHP Static Code ReviewPHP Static Code Review
PHP Static Code Review
 
Web app development_php_04
Web app development_php_04Web app development_php_04
Web app development_php_04
 
PHP Tutorial (funtion)
PHP Tutorial (funtion)PHP Tutorial (funtion)
PHP Tutorial (funtion)
 
DIWE - Advanced PHP Concepts
DIWE - Advanced PHP ConceptsDIWE - Advanced PHP Concepts
DIWE - Advanced PHP Concepts
 
07-PHP.pptx
07-PHP.pptx07-PHP.pptx
07-PHP.pptx
 
07-PHP.pptx
07-PHP.pptx07-PHP.pptx
07-PHP.pptx
 
Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3
 
The Art Of Readable Code
The Art Of Readable CodeThe Art Of Readable Code
The Art Of Readable Code
 
Php101
Php101Php101
Php101
 
07 php
07 php07 php
07 php
 
Presentaion
PresentaionPresentaion
Presentaion
 
Headless Js Testing
Headless Js TestingHeadless Js Testing
Headless Js Testing
 
PHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginnersPHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginners
 
Synapse india basic php development part 1
Synapse india basic php development part 1Synapse india basic php development part 1
Synapse india basic php development part 1
 
PHP security audits
PHP security auditsPHP security audits
PHP security audits
 
Php basic for vit university
Php basic for vit universityPhp basic for vit university
Php basic for vit university
 
Php 26
Php 26Php 26
Php 26
 
Web Technology_10.ppt
Web Technology_10.pptWeb Technology_10.ppt
Web Technology_10.ppt
 

Mehr von Spy Seat

Kazdoura & Luciano Jan – Aug 2016 Cost Analysis
Kazdoura & Luciano  Jan – Aug 2016 Cost AnalysisKazdoura & Luciano  Jan – Aug 2016 Cost Analysis
Kazdoura & Luciano Jan – Aug 2016 Cost AnalysisSpy Seat
 
Software Design
Software DesignSoftware Design
Software DesignSpy Seat
 
Visual Basic 6 Data Base
Visual Basic 6 Data BaseVisual Basic 6 Data Base
Visual Basic 6 Data BaseSpy Seat
 
Visual Basic ADO
Visual Basic ADOVisual Basic ADO
Visual Basic ADOSpy Seat
 
Visual basic 6
Visual basic 6Visual basic 6
Visual basic 6Spy Seat
 
Create Contacts program with VB.Net
Create Contacts program with VB.NetCreate Contacts program with VB.Net
Create Contacts program with VB.NetSpy Seat
 
Create Your first website
Create Your first websiteCreate Your first website
Create Your first websiteSpy Seat
 
How Computer work
How Computer workHow Computer work
How Computer workSpy Seat
 
visual basic 6 Add Merlin
visual basic 6 Add Merlin visual basic 6 Add Merlin
visual basic 6 Add Merlin Spy Seat
 
My Bachelor project slides
My Bachelor project slides My Bachelor project slides
My Bachelor project slides Spy Seat
 
Difference between asp and php
Difference between asp and phpDifference between asp and php
Difference between asp and phpSpy Seat
 
Error handling
Error handlingError handling
Error handlingSpy Seat
 
I/O PHP Files and classes
I/O PHP Files and classesI/O PHP Files and classes
I/O PHP Files and classesSpy Seat
 
Php session 3 Important topics
Php session 3 Important topicsPhp session 3 Important topics
Php session 3 Important topicsSpy Seat
 
Notify progresscontrol
Notify progresscontrolNotify progresscontrol
Notify progresscontrolSpy Seat
 
Listbox+checkedlistbox
Listbox+checkedlistboxListbox+checkedlistbox
Listbox+checkedlistboxSpy Seat
 
If then vs select case
If then vs select caseIf then vs select case
If then vs select caseSpy Seat
 
If then vb2010
If then vb2010If then vb2010
If then vb2010Spy Seat
 
Date & time picker
Date & time pickerDate & time picker
Date & time pickerSpy Seat
 

Mehr von Spy Seat (20)

Kazdoura & Luciano Jan – Aug 2016 Cost Analysis
Kazdoura & Luciano  Jan – Aug 2016 Cost AnalysisKazdoura & Luciano  Jan – Aug 2016 Cost Analysis
Kazdoura & Luciano Jan – Aug 2016 Cost Analysis
 
Software Design
Software DesignSoftware Design
Software Design
 
Visual Basic 6 Data Base
Visual Basic 6 Data BaseVisual Basic 6 Data Base
Visual Basic 6 Data Base
 
Visual Basic ADO
Visual Basic ADOVisual Basic ADO
Visual Basic ADO
 
Visual basic 6
Visual basic 6Visual basic 6
Visual basic 6
 
Create Contacts program with VB.Net
Create Contacts program with VB.NetCreate Contacts program with VB.Net
Create Contacts program with VB.Net
 
Create Your first website
Create Your first websiteCreate Your first website
Create Your first website
 
How Computer work
How Computer workHow Computer work
How Computer work
 
visual basic 6 Add Merlin
visual basic 6 Add Merlin visual basic 6 Add Merlin
visual basic 6 Add Merlin
 
My Bachelor project slides
My Bachelor project slides My Bachelor project slides
My Bachelor project slides
 
Difference between asp and php
Difference between asp and phpDifference between asp and php
Difference between asp and php
 
Error handling
Error handlingError handling
Error handling
 
I/O PHP Files and classes
I/O PHP Files and classesI/O PHP Files and classes
I/O PHP Files and classes
 
Php session 3 Important topics
Php session 3 Important topicsPhp session 3 Important topics
Php session 3 Important topics
 
Notify progresscontrol
Notify progresscontrolNotify progresscontrol
Notify progresscontrol
 
Listbox+checkedlistbox
Listbox+checkedlistboxListbox+checkedlistbox
Listbox+checkedlistbox
 
If then vs select case
If then vs select caseIf then vs select case
If then vs select case
 
If then vb2010
If then vb2010If then vb2010
If then vb2010
 
For next
For nextFor next
For next
 
Date & time picker
Date & time pickerDate & time picker
Date & time picker
 

Kürzlich hochgeladen

Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxJanEmmanBrigoli
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxElton John Embodo
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxruthvilladarez
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
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.
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 

Kürzlich hochgeladen (20)

Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptx
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docx
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docx
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
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...
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 

Conditional Statementfinal PHP 02

  • 1. PHP Course 2: Conditional Statements PHP Course Info@ITBigDig.com
  • 2. Instructor  Name: Mohamed Saad.  Email: Engsaad_aly@hotmail.com  Occupation: Web Developer In IT Big Dig. PHP Course Info@ITBigDig.com
  • 3. Contents • PHP Array o Introduction. • Conditional Statements. o if statement. o if...else statement. o if...else if....else statement. o switch statement. PHP Course Info@ITBigDig.com
  • 4. PHP Array • There are three types of arrays: Indexed arrays •Arrays with numeric index Associative arrays • Arrays with named keys Multidimensional arrays •Arrays containing one or more arrays
  • 6.
  • 7. <pre> <?php $x = array ('saad','nacer city','zkzk@hotmail'); print_r ($x); Copy Code outputdata.php $y = array ('name' => 'saad', 'address' => 'nacer city', 'email' => array ('zkzk@hotmail', 'zkzk@yahoo', 'zkzk@gmail')); print_r ($y); ?> </pre> PHP Course Info@ITBigDig.com
  • 8. Conditional Statements 1) if statement - executes some code only if a specified condition is true. 2) if...else statement - executes some code if a condition is true and another code if the condition is false. 3) if...else if....else statement - selects one of several blocks of code to be executed. 4) switch statement - selects one or more of many blocks of code to be executed.
  • 9. if statement Syntax o if (condition) { code to be executed if condition is true; } PHP Course Info@ITBigDig.com
  • 11. HTML PHP Dig: Check value entered by user.
  • 12.
  • 13. <html> <body> Copy Code game.php <form action="game.php" method="post"> Enter number between 1 and 100:<input type="text" name="x"/> <input type="submit" name="submit" value="xxx"/> </form> </body> </html> <?php if (empty($_POST)===false) { $x=$_POST['x']; if($x>50) { echo 'U Entered Number ',$x,' greater than 50','<br>'; echo 'U Entered Number '.$x.' greater than 50'; exit(); } } ?> PHP Course Info@ITBigDig.com
  • 14. Getdate Function Syntax <?php timestamp print_r(getdate( )); ?> o getdate(timestamp); • Timestamp o Default (time()) o “U” Specifies an integer Unix timestamp
  • 15.
  • 16. Key "seconds" "minutes" "hours" "mday" "wday" "mon" Returned Values 0 to 59 0 to 59 0 to 23 1 to 31 0 (for Sunday) 1 through 12 "year" Examples: 1970 or 2011 "yday" 0 through 365 "weekday" Sunday through Saturday "month" January through December 0 Unix Epoch: is a system for describing points in time -2147483648 through 2147483647.
  • 17. <pre> Copy Code <?php Conditional_statement.php print_r(getdate()); echo '<br/>'; $mydate=getdate(date(time())); echo"--------------------------------------------"; echo"<br/>"; echo "date: $mydate[weekday], $mydate[month] $mydate[mday], $mydate[year]"; echo"<br/>"; echo "time: H:$mydate[hours], M:$mydate[minutes], S:$mydate[seconds]"; echo"<br/>"; if ($mydate[“mday”]>=20) { echo"--------------------------------------------"; echo"<br/>"; echo "we are at the end of the month"; } ?> </pre> PHP Course Info@ITBigDig.com
  • 20. Is Associative • If set to FALSE or not supplied then the array is returned as a regular, numerically indexed array. If the argument is set to TRUE then localtime() returns an associative array containing all the different elements of the structure returned by the C function call to localtime.
  • 21. if...else Statement Syntax if (condition) { code to be executed if condition is true; } else { code to be executed if condition is false; } PHP Course Info@ITBigDig.com
  • 22.
  • 23. <?php Copy PHP Code if (empty($_POST)===false) { $x=$_POST['x']; if ($x>50){ echo 'U Entered Number ',$x,' greater than 50','<br>'; exit(); } else { echo 'U Entered Number ',$x,' less than 50','<br>'; exit(); } } ?>
  • 24. if...else if....else Statement Syntax if (condition) { } else if (condition) { } elss { }
  • 25.
  • 26. <html> Copy Code <body> game.php <form action="game.php" method="post"> Enter number between 1 and 100:<input type="text" name="x"/> <input type="submit" name="submit" value="Go"/> </form> </body> </html> <?php if (empty($_POST)===false) { $x=$_POST['x']; if($x>50){ echo 'U Entered Number ',$x,' greater than 50','<br>'; exit(); }else if($x<50){ echo 'U Entered Number ',$x,' less than 50','<br>'; exit(); }else { echo 'U Entered Number ',$x; exit(); } } ?>
  • 27. I think it`s clear now…! PHP Course Info@ITBigDig.com
  • 29. Switch statement Syntax o switch (n) { case label1: code to be executed if n=label1; break; case label2: code to be executed if n=label2; break; default: code to be executed if n is different from both label1 and label2; }
  • 30. Switch statement Power Syntax o switch (variable) { case (condition): code to be executed if condition is true; break; case (condition): code to be executed if condition is true; break; default: All conditions are false; }
  • 31.
  • 32. <?php $x="red"; switch ($x) { case "blue": echo "Your favorite color is blue!"; break; case "red": echo "___________________<br>"; echo "Your favorite color is red!"; break; case "green": echo "Your favorite color is green!"; break; default: echo "no matching color!"; } Copy Code switch2.php ?> PHP Course Info@ITBigDig.com
  • 34. <?php Copy Code switch.php $hours = date("H"); $hours=$hours-2; echo $hours,date(":i:s"); echo "<br/>"; ?> <?php switch ($hours) { case ($hours>5 and $hours<6): echo "it is the time of the TV News <br/>"; case ($hours>=6 and $hours<8): echo "Read something<br/>"; case ($hours>=8 and $hours<10): echo "PlayStation time<br/>"; default: echo "GoodNight"; } ?> PHP Course Info@ITBigDig.com
  • 35. Character Description Expected O/P d Day of the month, j Day of the month without leading zeros D l A textual representation of a day 2 digits Returned Values 01 to 31 1 to 31 Three letters Mon through Sun A full textual representation of the day Sunday through of the week it is lowercase “L” Saturday N ISO-8601 numeric representation of the day of the week (PHP 5.1.0) S English ordinal suffix for the day of the month, z The day of the year 1 digit 1 (for Monday) through 7 (for Sunday) 2 characters st, nd, rd or th. 0 through 365
  • 36. For complete reference Go To http://php.net/manual/en/function.date. php PHP Course Info@ITBigDig.com
  • 37. End Conditional Statements We hope You enjoy This Tutorial. For any Suggestions Please Email Us Info@ITBigDig.com PHP Course Info@ITBigDig.com