Old 07-05-2007   #1 (permalink)
Steven
 
Join Date: Jun 2005
Location: McAlester, OKlahaoma - United States
Posts: 21

Thumbs down If Else Statements - A PHP classic?

This tutorial contains terms that even the begginer php coder should know. I will not be explaining every single term. If there are any questions simply post them, and they will be answered.


An if else statement is used to basicly check to see if something is true or false. An if else statement could be used to ask 'if $variable is true then do this, otherwise the variable is false so do something else. You could of course ask 'if variable is false do this, otherwise do something else...
--------------------------
Now I will be showing, and explaining an example of the if else code.

Let's say you have five dollars and you want to know what you could afford.

First let's go over the different symbols used in an if else statement.

== Is equal to (two equal signs)
!= (or) <> Is not equal to
> Is greater than
< Is less than
>= Is greater than or equal to
<= Is less than or equal to


I will be using two variables to demonstrate what can, and cannot be afforded.
I will use the '$fivedollars' variable to set the ammount of money you have, and I will use the '$item' variable to deomonstrate the price of the item you want to buy.

PHP Code:
<?php  
$fivedollars 
5;
$item 5.01;

if (
$item $fivedollars) {  
echo 
"You can afford this.";   
} else {  
echo 
"You cannot afford this.";  
}  ;
?>
The code is very simple.

These two are your variables:
$fivedollars = 5;
$item = 5.01;


This asks if the item is less than five dollars, and if so to output the message "You can afford this."
if ($item < $fivedollars) {
echo "You can afford this.";
}


This asks if the item is more than five dollars, and if so to output the message "You cannot affor this."


I understand this is very simple, and probably not as well organized, and thought out as possible.. I'm just trying to emphasize the importance on simple functions such as the if else statement.
__________________
--
Steven

Last edited by basicwe; 07-05-2007 at 05:27 AM.
basicwe is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Macronimous- Command Line Scripting in PHP macro123 HTML / PHP / ASP / JS 1 03-30-2007 02:50 AM
PHP in HTML ultranet HTML / PHP / ASP / JS 3 01-04-2007 09:07 AM
Ajax and PHP sanjitster HTML / PHP / ASP / JS 2 06-03-2006 04:22 AM
Pro's and Con's to Upgrading PHP pipersdragon HTML / PHP / ASP / JS 1 12-29-2005 11:43 PM
Digital's Quick and Dirty Guide to PHP Order HTML / PHP / ASP / JS 15 05-05-2004 01:18 AM


All times are GMT +1. The time now is 05:03 AM.
Content Relevant URLs by vBSEO 3.2.0 RC7

Design & Content © BioRUST 2007 :: PRIVACY STATEMENT :: LEGAL INFORMATION :: ADVERTISING MEDIA KIT