apparition.Designs | version 2 | anything you can imagine is real

.Welcome to apparition.Designs [apparitiondesigns.com]

Hello, we are currently under development and are trying to get all our content up as soon as possible. We hope to get the site up, tweaked, and bug-free A.S.A.P. If you have any questions or comments on what you have (or havent) seen so far, feel free to email me at StratzSfear@apparitionDesigns.com

 
 

.Learning if elseif and else

Lets start with "if"... An if statement determins the results of a test, and then tells the script what to do after. If that doesn't make total sense, maybe this will help:


<?php
$sound 
"moo" //makes $sound = moo
if ( $sound == "moo" //tests if the variable cow is equal to moo
{
    echo 
"The sound is that of a cow";
}
?>
                    

Will show:
The sound is that of a cow

In this case, it will test to see if the variable $cow is equal to "moo" and if it is, it will continue parsing (running) the code in between the curley brackets "{ }"

Now, the if statement ( between the round brackets "( )") can sometimes be false, so we need to come up with a way to deal with it, if it ends up somthing that we do not know. We now will deal with "else"...


<?php
$sound 
"mikoi"    //makes $sound = moo
if ( $sound == "moo" )    //tests if the variable sound is equal to moo
{
    echo 
"The sound is that of a cow"//run the code if the result of the if test is true
}
else    
{
    echo 
"I don't know what makes that sound!";
}
?>
                    

Will show:
I don't know what makes that sound!

Here we don't know what makes that sound. When it goes through the if test, it results in "false" so it skips over everything in the if's curley brackets, and moves to the else's curley brackets.

Some times there is more than one option that we would like to test for. We clearly know more sounds that just moo, so lets try adding more options with "elseif"...

"elseif" - in english - pretty much says "or else, if"


<?php
$sound 
"ribbit"    //makes $sound = moo
if ( $sound == "moo" )    //tests if the variable sound is equal to moo
{
    echo 
"The sound is that of a cow"//run the code if the result of the if test is true
}
elseif ( 
$sound == "meow" )    //test if the sound variable is meow
{
    echo 
"Sounds like a cat to me!";
}
elseif ( 
$sound == "ribbit" )    //test to see if the sound variable is ribbit
{
    echo 
"That seems to be a frog you got there..."
}
else    
//if it is STILL not a sound we know... display this    
{
    echo 
"I don't know what makes that sound!";
}
?>
                    

Will show:
That seems to be a frog you got there...

This not only tests if the sound is moo, but also: meow and ribbit. Having finaly 'passed a test' (the elseif ($sound == "ribbit") test) it goes and executes the code for that option.

Just a little side note, if you are having problems remembering what "=" means and what "==" means, when you see "=" think of the word "is", and when you see "==" think of "is equal to".

Now of course, you can test a great many more things, and you can put a lot more inbetween each curley bracket, but this is just a tutorial to help get you on your way...

** If you are still having problems, please note a few things...
1) each line of code ends with a ";" (semi-colon)
2) Variables are case sensitive ie. $a is not the same as $A
3) Make sure you use round brackets for the "if", and "elseif" tests, and curley brackets for after the "if", "elseif" and "else"