PHP

 Home  Computers & Internet  Web Programming PHP
What is PHP?
Echo
Comments
Variables
Constants
Data Types
number_format()
Character Strings
Mathematical Operators
Comparison Operators
Logical Operators
Joining Strings
explode()
implode()
strtolower()
strtoupper()
strlen()
ucfirst()
ucwords()
strrev()
str_replace()
str_repeat()
trim()
strip_tags()
addslashes()
stripslashes()
strpos()
strrpos()
nl2br()
isset()
unset()
empty()
POST
GET
If Statements
If Else Statements
Elseif Statements
Switch Statements
For Loops
While Loops
Do While Loops
Foreach Loops
File Create
File Open
File Read
File Write
File Delete
fgets()
file_get_contents()
Date & Time
$_SERVER
Sessions
Cookies
Arrays

HOW TO USE if STATEMENTS IN PHP

If statements execute a certain specified block of code only if a certain specified condition is true. The general format is as follows:

if (certain condition is true)

{

specified block of code to execute

}

Example:

$lastName="Bond";

if ($lastName=='Bond')

{

echo "Are you related to James?";

}

Only if the specified condition of $lastName=='Bond' is true, will the block of code {between the curly braces} execute which, in this example, is to echo Are you related to James?

In the above case, $lastName is Bond (as we declared it at this line: $lastName="Bond";) so therefore the block of code {between the curly braces} will execute.

If $lastName was not Bond, the block of code {between the curly braces} won't execute and nothing is outputted as below.

Example:

$lastName="Smith";

if ($lastName=='Bond')

{

echo "Are you related to James?";

}

Nothing is outputted.

Home | Privacy Policy | Terms Of Use | Contact Us