Monday, August 3, 2009

PHP Conditional Statements

Basics of PHP '" Part 4Introduction
This is conception 4 of my series, Basics of PHP. In this conception of the series, we wager how a assemble of statements crapper be executed supported on a condition. It is kindred to what happens in a manlike language. For example, somebody crapper say, if a information is true, do that and that and that.

Note: If you cannot wager the cipher or if you conceive anything is abstracted (broken link, ikon absent), meet occurrence me at forchatrans@yahoo.com. That is, occurrence me for the slightest difficulty you hit most what you are  reading.

The if Statement
In PHP, there is a distant word, which is "if". The "if" staleness be in lowercase. This is utilised to check if a information is true. If it is true, digit or more statements are executed. Let us countenance at an example. Consider the mass statements:

The prototypal evidence assigns the continuance 20 to the variable, $hisVar. Then you hit the "if" statement. The if-statement begins with the distant word, "if" and ends with the frizzy brace, }. What goes exclusive the parentheses is the condition. The statements to be executed are in the frizzy braces. If there is exclusive digit statement, you do not requirement the frizzy braces. If you hit more than digit statement, removed them with semicolons and place them within the frizzy braces, {}.

If the information is correct, PHP module change it with, true, internally; you do not wager it. If it is wrong, PHP module change it with, false, internally.

In the above code, 20 was appointed to, $hisVar. So, $hisVar equals 20. In the information the coequal clew is digit naming operators: digit meet incoming to the other. The if-statement above crapper be feature same this: if $hisVar equals 20 then display, 'I am studying PHP'. Since we appointed the continuance 20 to $hisVar, the information of the if-statement is true. So the evidence in the frizzy braces is executed. Try the above code


No comments:

Post a Comment