SlideShare a Scribd company logo
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’, );
Conditional Statementfinal PHP 02
<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.
Conditional Statementfinal PHP 02
<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
Conditional Statementfinal PHP 02
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
Conditional Statementfinal PHP 02
<?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 {
}
Conditional Statementfinal PHP 02
<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;
}
Conditional Statementfinal PHP 02
<?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

More Related Content

PDF
Asssignment2
PDF
Hacker News vs. Slashdot—Reputation Systems in Crowdsourced Technology News
PDF
Programming with GUTs
PDF
Sasha Romijn - Everything I always wanted to know about crypto, but never tho...
PPT
PHP - Web Development
PDF
Functional C++
RTF
cs8project
PDF
Beyond Good & Evil: The nuts and bolts of DRM - Dave Cramer - ebookcraft 2017
Asssignment2
Hacker News vs. Slashdot—Reputation Systems in Crowdsourced Technology News
Programming with GUTs
Sasha Romijn - Everything I always wanted to know about crypto, but never tho...
PHP - Web Development
Functional C++
cs8project
Beyond Good & Evil: The nuts and bolts of DRM - Dave Cramer - ebookcraft 2017

What's hot (20)

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

Similar to Conditional Statementfinal PHP 02 (20)

PPT
Chapter 03 conditional statements
PPTX
advancing in php programming part four.pptx
PPTX
Php Basics Iterations, looping
PPSX
Php and MySQL
PPT
slidesharenew1
PPT
My cool new Slideshow!
PPT
Php mysql
PPTX
Lecture 9 - Intruduction to BOOTSTRAP.pptx
PPTX
unit 1.pptx
PPTX
Statements and Conditions in PHP
PPTX
Introduction in php part 2
PPTX
Php.ppt
PPTX
Intro to php
PPT
Php mysql
PPTX
Web Application Development using PHP Chapter 2
PPT
Class 2 - Introduction to PHP
PDF
PHP-Part2
PPTX
php programming.pptx
PPTX
Conditional Code (Day-1) Looping & Condition
Chapter 03 conditional statements
advancing in php programming part four.pptx
Php Basics Iterations, looping
Php and MySQL
slidesharenew1
My cool new Slideshow!
Php mysql
Lecture 9 - Intruduction to BOOTSTRAP.pptx
unit 1.pptx
Statements and Conditions in PHP
Introduction in php part 2
Php.ppt
Intro to php
Php mysql
Web Application Development using PHP Chapter 2
Class 2 - Introduction to PHP
PHP-Part2
php programming.pptx
Conditional Code (Day-1) Looping & Condition
Ad

More from mohamedsaad24 (20)

PPTX
Kazdoura & Luciano Jan – Aug 2016 Cost Analysis
PPTX
Software Design
PPT
Visual Basic 6 Data Base
PPT
Visual Basic ADO
PPTX
Visual basic 6
PPTX
Create Contacts program with VB.Net
PPTX
Create Your first website
PPT
How Computer work
PPT
visual basic 6 Add Merlin
PPTX
My Bachelor project slides
PPTX
Difference between asp and php
PPTX
Error handling
PPTX
I/O PHP Files and classes
PPTX
Php session 3 Important topics
PPT
Notify progresscontrol
PPT
Listbox+checkedlistbox
PPT
If then vs select case
PPT
If then vb2010
PPT
For next
PPT
Date & time picker
Kazdoura & Luciano Jan – Aug 2016 Cost Analysis
Software Design
Visual Basic 6 Data Base
Visual Basic ADO
Visual basic 6
Create Contacts program with VB.Net
Create Your first website
How Computer work
visual basic 6 Add Merlin
My Bachelor project slides
Difference between asp and php
Error handling
I/O PHP Files and classes
Php session 3 Important topics
Notify progresscontrol
Listbox+checkedlistbox
If then vs select case
If then vb2010
For next
Date & time picker

Recently uploaded (20)

PDF
Computing-Curriculum for Schools in Ghana
PDF
Classroom Observation Tools for Teachers
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Lesson notes of climatology university.
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Institutional Correction lecture only . . .
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
master seminar digital applications in india
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
Computing-Curriculum for Schools in Ghana
Classroom Observation Tools for Teachers
Module 4: Burden of Disease Tutorial Slides S2 2025
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
FourierSeries-QuestionsWithAnswers(Part-A).pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Supply Chain Operations Speaking Notes -ICLT Program
Chinmaya Tiranga quiz Grand Finale.pdf
O7-L3 Supply Chain Operations - ICLT Program
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Lesson notes of climatology university.
Complications of Minimal Access Surgery at WLH
Institutional Correction lecture only . . .
102 student loan defaulters named and shamed – Is someone you know on the list?
master seminar digital applications in india
2.FourierTransform-ShortQuestionswithAnswers.pdf
Microbial disease of the cardiovascular and lymphatic systems

Conditional Statementfinal PHP 02