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
 
Presentaion
PresentaionPresentaion
Presentaion
 
07 php
07 php07 php
07 php
 
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

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 

Kürzlich hochgeladen (20)

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

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