1. Trang chủ
  2. » Mẫu Slide

Slide môn học PHP session 2c conditional statements in PHP

18 171 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 18
Dung lượng 161 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

the statements in a program execute from the first to the last statement order of flow in a program set of statements only when a... if statementthe specified condition is true condition

Trang 1

Conditional Statements in PHP

Session 7

Trang 2

 Operators are pre-defined symbols that enable us perform specific actions

 Operators enable us to control the

program flow

 The types of operators are:

 Arithmetic operators

 Logical Operators

 Relational Operators

 Bitwise Operators

 Assignment Operators

Review - I

Trang 3

Review - II

 Arithmetic operators are used to perform mathematical operations

 Relational operators compare two operands and determine the relationship between

operands

 Logical operators handle multiple

conditions and combines two or more test expression in a condition

 Bitwise operators operate on the bits of

Trang 4

Objectives

Trang 5

the statements in a program execute

from the first to the last statement

order of flow in a program

set of statements only when a

Trang 6

if statement

the specified condition is true

condition is false

if(condition)

// Code executes if the condition is true

Trang 7

if statement - Example

$a=50;

$b=100;

if($a < $b)

echo "a is less than b";

$a < $b

PHP displays, a is less than b

Trang 8

if …else statement

specified condition is false

if(condition)

{

//Code executes if the condition is true }

else

{

//Code executes if the condition is false

Trang 9

if …else statement - Example

if($a < $b)

{

echo “A is less than B”;

}

else($a > $b)

{

echo “B is less than A”;

}

Trang 10

Nested if statement

else statement

if(condition)

{

//code to be executed }

else

{

//code to be executed if(condition)

{

//code to be executed

Trang 11

Nested if statement - Example

if($a < 500)

{

echo “A is les than 500”;

}

else

{

if ($a >= 500 and $a <= 700)

{

echo “A is between 500 and 700”;

else

{

Trang 12

switch statement - I

multiple values

the value it matches

value of the case statement

matches the value of the switch

variable

Trang 13

Syntax of switch statement

switch(variable)

{

case value1:

//Code executes if condition equals value1

break;

case value2:

//Code executes if condition equals value2

break;

default:

Moves the control to the statements

Trang 14

Example for a switch Statement

switch($var)

{

case Minor:

echo “Not eligible to vote”;

break;

case Major:

echo “Eligible to vote”;

break;

default:

echo “Enter correct value”;

break;

};

Trang 15

Ternary Operator

one line statements

Term1 ? Term2 : Term3;

Term1 - Condition is evaluated

Term2 - Executed if condition is True

Trang 16

Example of Ternary Statement

$x = 100;

$y = 50;

$disp =

($x > $y) ? “X is greater than Y” : “Y is greater than X”;

Condition checked

Trang 17

Summary - I

 Conditional statements execute a set of

statements only when a specified

condition is satisfied

 if statement executes a block of code

only when the specified condition is true

 In a Nested if statement, we specify if

statement within if statement or else

statement

 switch statement checks single variable

against multiple values

switch statement executes a block of code

Trang 18

Summary - II

the statements following the switch statement

of the case statements matches the

value of the switch variable

conditions into one line statements

Ngày đăng: 30/11/2016, 22:11

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN