Page 81 - Open Soource Technologies 304.indd
P. 81
Unit 3: Flow-Control Statements and PHP in Web Page
• The switch statement, in its structure, is similar to the if statement. It takes an expression Notes
to be evaluated and a statement block.
• A do ... while statement is like a while statement in reverse. First it runs the block of code,
and then it evaluates the conditional expression. If the conditional expression is true, then
it loops back to the beginning of the statement and starts again.
• PHP gives the option to step out of multiple levels when working with nested conditional
iterative statements. Once again, the if statement is not included in the since it is used to
test whether to make such a step.
• Code in an included file is imported at the scope that is in effect where the include statement
is found, so the included code can see and alter your code’s variables.
3.8 Keywords
If statement: If statement is a simple concept. If something is true, then perform the statement
block associated with it, otherwise do not.
Phonic similarity: Phonic similarity just means that things are compared based on whether they
sound alike. To compare things by how they sound you can use one of two functions.
Textual similarity: Textual similarity is a little more useful because it allows you to compare how
similar two text strings are.
The default condition: The default keyword is a catch-all case that marks the point to begin
execution of none of the conditions being tested for is met. It is like the last else statement in a
long string of else if’s.
The else statement: The else statement can only follow an if statement and is used to mark off a
statement block to execute if the conditional expression being tested evaluates to false.
The elseif statements: This allows us to test for another condition if the first one was not true.
1. Create PHP programs to show the use of conditional statements.
2. Develop a PHP program using switch statement.
3.9 Review Questions
1. What are the conditional statements? Explain with example.
2. Define the switch and case statements.
3. How do we compare two strings? Explain the functions.
4. What is the difference between strcasecmp(str1, str2);, strnatcmp(str1, str2); and
strnatcasecmp(str1, str2); ?
5. What is the similarity? Explain the phonic and text similarity.
6. What are the iterative statements? Differentiate between them.
7. What are the termination statements? When are these used?
8. Differentiate between break and continue statements.
9. How is the PHP code embedded in HTML or XML files?
10. Develop a program to embedding the PHP code in HTML.
LOVELY PROFESSIONAL UNIVERSITY 75