Decision and looping examples with php (WT)

344 views 15 slides Feb 23, 2020
Slide 1
Slide 1 of 15
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15

About This Presentation

under web technology subject. decision statements and looping statements in Php server-side language. very close to C language's statements.


Slide Content

Decision and looping examples with PHP Kunjan Shah TY CE 2 Batch C 170410107103

Introduction to PHP PHP stands for Hypertext Preprocessor. PHP is a server side scripting languages that allows you to create dynamic web pages. It is free to download and use. You can embed PHP scripting within normal html coding. It is mainly used for form handling and database access. The extension to the PHP files are .php, .php3 or .phtml and .php4 as well.

Basics of PHP PHP code is contained within tags <?php ?> or short open: <? ?> PHP with HTML echo is a command in PHP for writing output data to the browser, and at the end of each PHP statement we require to write a ; (semicolon) as you see in the below example code. Otherwise, if you write another statement, then PHP will report a syntax error. <?php echo "Hello World"; ?> </body> Comments // for single line /* */ for multiline

DECISION MAKING STATMENTS The if, elseif ...else and switch statements are used to take decision based on the different condition. You can use conditional statements in your code to make your decisions. PHP if..else statement : PHP  if statement  is used to execute some code, if a condition is evaluated to  true  otherwise if the condition is evaluated to false, execute nothing, or execute some other code.

The If...Else Statement

The ElseIf Statement If you want to execute some code if one of the several conditions are true use the elseif statement

The Switch Statement If you want to select one of many blocks of code to be executed, use the Switch statement. The switch statement is used to avoid long blocks of if..elseif..else code. The  switch  statement works in an unusual way. First it evaluates given expression then seeks a label to match the resulting value. If a matching value is found then the code associated with the matching label will be executed or if none of the label matches then statement will execute any specified default code.

The Switch Statement

Looping Statements Loops in PHP are used to execute the same block of code a specified number of times. PHP supports following four loop types. for  − loops through a block of code a specified number of times. while  − loops through a block of code if and as long as a specified condition is true. do...while  − loops through a block of code once, and then repeats the loop as long as a special condition is true. foreach  − loops through a block of code for each element in an array.

The for loop statement

The while loop statement

The do...while loop statement

The foreach loop statement The foreach statement is used to loop through arrays. It loops over the array, and each value for the current array element is assigned to $value, and the array pointer is advanced by one to go the next element in the array.

The foreach loop statement

t hank you 