PHP Tutorial Example
Example
PHP Mail
PHP Libxml
PHP HTTP
PHP Filter
PHP Zip
PHP Directory
PHP Error
PHP SimpleXML
PHP Calendar
PHP Date
PHP Misc
PHP XML
PHP FTP
PHP Math
PHP MySQL
PHP Filesystem
PHP Array
PHP String
PHP Tutorial
PHP Introduction
PHP Installation
PHP Syntax
PHP Variables
PHP Echo
PHP Strings
PHP Operators
PHP Comments
PHP Include File
PHP Require
PHP If Statement
PHP If Else
PHP Elseif
PHP Switch
PHP Forms
PHP Functions
PHP Array
PHP While Loop
PHP For Loop
PHP For Each
PHP Do While
PHP POST and GET
PHP Magic Quotes
PHP htmlentities
PHP Files
PHP File
PHP File Create
PHP File Open
PHP File Close
PHP File Write
PHP File Read
PHP File Delete
PHP File Append
PHP File Truncate
PHP File Upload
PHP Strings
PHP strpos
PHP str replace
PHP substrreplace
PHP Capitalization
PHP explode
PHP implode
PHP Advanced
PHP Date
PHP Session
PHP Cookies
PHP Include
PHP Email
PHP Secure Email
PHP Error
PHP Exception
PHP Filter
PHP and AJAX
AJAX Intro
AJAX PHP
AJAX Database
AJAX XML
AJAX Live Search
AJAX RSS Reader
AJAX Poll
PHP XML
XML Expat Parser
XML DOM
XML SimpleXML
PHP Database
MySQL Introduction
MySQL Connect
MySQL Create
MySQL Insert
MySQL Select
MySQL Where
MySQL Order By
MySQL Update
MySQL Delete
PHP ODBC
PHP Misc
PHP connection aborted Function
Has someone ever told you, "if you work hard, then you will succeed"? And what happens if you do not work hard? Well, you fail! This is an example of an if/else conditional statement.
* If you work hard then you will succeed.
* Else, if you do not work hard, then you will fail.
How does this translate into something useful for PHP developers? Well consider this:
Someone comes to your website and you want to ask this visitor her name if it is her first time coming to your site. With an if statement this is easy. Simply have a conditional statement to check, "are you visiting for the first time". If the condition is true, then take them to the "Insert Your Name" page, else let her view the website as normal because you have already asked her for her name in the past.that is know as if else conditions
Using these conditional statements can add a new layers of "cool" to your website. Here's the basic form of an if/else statement in PHP.
$number_three = 3;
if ( $number_three == 3 ) {
echo "The if statement evaluated to true, only for 3 value ";
} else {
echo "The if statement evaluated to false";
}
This is a lot to digest in one sitting, so let us step through the code, line by line.
* We first made a PHP variable called $number_three and set it equal to 3.
* In this example we compared a variable to an integer value. To do such a comparison we use "==", which in English means "Is Equal To".
* $number_three is indeed Equal To 3 and so this statement will evaluate to true.
* All code that is contained between the opening curly brace "{" that follows the if statement and the closing curly brace "}" will be executed when the if statement is true.
* The code contained within the else segment will not used.
On the other hand, if the if statement was false, then the code contained in the else segment would have been executed. Note that the code within the if and else cannot both be executed, as the if statement cannot evaluate to both true and false at one time! Here is what would happen if we changed to $number_three to anything besides the number 3.
first of all condition will tested . if the condition will true the body of loop will be executed otherwise the else statement will be executed.
$number_three = 419;
if ( $number_three == 3 ) {
echo "The if statement evaluated to true";
} else {
echo "The if statement evaluated to false";
}
The variable was set to 419, which is not equal to 3 and the if statement was false. As you can see, the code segment contained within the else was used in this case.

