Wednesday, April 27, 2011

Understanding Operators | PHP If, Else and Elsif

Just a reminder, until this moment you already have some basic skills in PHP if that is how to program PHP, Variables and Arrays. With the variables you have to connect between the PHP pages, plus an array, it seems you already have all the knowledge of PHP,
There is still much we can learn. One of the important part is to study the operator, which in this section the operator to be discussed is the If and else. Why is operators that important? Because they are allowing a program to decide and "thinking " (of course appropriate that we have set).

Ready? Let us begin by trying to get acquainted with "if".

"If"
How to make your page into "smart" is to use command If, Else and elseif are accompanied by logical operators and comparison. The most important is if the command, which allows you to create code like this
:
  • If a condition is true, then do something;
  • If the condition is false, then just ignore
The syntax for the above statement is as follows:


Here is an example which is more real. First we will set the variable $ WarnaKesukaan with the blue (line 3). Then we would say "If WarnaKesukaan is blue, then show 'I also like the color blue you know!'"

Else

Else is part of the command if, to say the following:

  • If a condition is true, then do something;or, if the first condition is not true, then do this other thing.
Example:

Here are
real examples of the continuation of the above:

What you see above is a common format in writing the statement. The key is to see where the curly brackets opps,,, braces
so you do not confuse such a command which is part of a specific code. In the code above, the pair {and} The first is the property "if ", while the {and} both belong to "else".

hope useful
.... see you again
read more...