SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

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
 

Tendances (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
 

Similaire à Conditional Statementfinal PHP 02

Similaire à 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
 
overview of php php basics datatypes arrays
overview of php php basics datatypes arraysoverview of php php basics datatypes arrays
overview of php php basics datatypes arrays
 
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
 

Plus de 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
 

Plus de 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
 

Dernier

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 

Dernier (20)

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 

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