Get support from Xavier Media
It is currently Sun Dec 08, 2013 3:40 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Lesson 10 - Review
PostPosted: Thu Jul 13, 2006 7:36 pm 

Points:
I would like to use this lesson to go back over what we have learned about variables, strings, and control structures. If you feel you have mastered these then you are welcome to skip this lesson.


So once again, a variable can be given any of the following values, any of the following ways:

[php] <?php
//Numbers:
$var1 = "993"; //$var1 is equal to 993
$var2 = 993; //$var2 is equal to 993
$var3 = '993'; //$var3 is equal to 993

//Letters:
$var4 = "G";
$var5 = 'G';

//Characters:
$var6 = '%';
$var7 = "+";

//Variables:
$var8 = '8';

$var9 = $var8;
//Variable 9 ($var9) is now equal to "8"

$var9++;
$var10 = $var9;
//Variable 10 is now equal to "9" ("8" plus one, or "++")

$var11 = $var10 + $var8;
//Variable 11 is now equal to 17

$var12 = ((0.1+0.7) * 10); // $var12 is equal to 8
$var13 = '((0.1+0.7) * 10)'; // $var12 is equal to "((0. 1+0.7)*10)"!
//Remember the '' means ABSOLUTE VALUE, while "" means PHP evaluates it.

?>[/php]


A variable can hold a letter or any number.



Strings hold long "strings" of letters or numbers - like as a sentence. All of the following are strings:


Sentences:
[php] <?php
$string1 = "Welcome to Learnphpfree.com";
$string2 = "5448 Longroad, Somewhere, CA 99999";
$string3 = "I love programming!?";

$string4 = "Learn";
$string5 = " PHP";
$string6 = " Free!";
$string7 = "$string4 $string5 $string6";
//String 7 is "Learn PHP Free!"

$string8 = "$var8 visitors to Learnphpfree.com";
//String 8 is equal to "8 visitors to Learnphpfree.com"

$string9 = $var11. " visitors to Learnphpfree.com". ' Since yesterday';
//String 9 is equal to "17 visitors to Learnphpfree.com Since yesterday"
?>[/php]

You will be doing a lot with strings so make sure and practice with them on your own so that you know them well.


Control Structures are the logic of the code. Remember that if the "if" is FALSE than PHP while run the "else" statement, but if the "if" is true PHP will ignore the "else" statement.

Remember that these characters dictate the control structure:

Code:
">" means "Greater than"
"<" means "less than"
"==" means "value is equal"
"=" means "make equal"
"&&" means "and"
"||" means "or"
"+" means "plus"
"-" means "minus"
"!" means "NOT"
"!=" means "NOT equal"
">+" means "Greater than or equal to"



Here are a couple simple ones:

[php] <?php
if (1 > 0) {
echo "1 is greater than 0";
} else {
echo "1 is not greater than 0";
}
//the "if" is TRUE because 1 is greater than 0



if (1 == 0) {
echo "1 is equal to 0";
} else {
echo "1 is not equal to 0";
}
//the "if" is FALSE because 1 is NOT equal to 0



if (1 != 0) {
echo "1 is not equal to 0";
} else {
echo "1 is equal to 0";
}
//the "if" is TRUE because 1 is NOT equal to 0



if (1 >= 0) {
echo "1 is greater than or equal to 0";
} else {
echo "1 is not greater than or equal to 0";
}
//the "if" is TRUE because 1 is greater or equal to 0
?>[/php]


ADVANCED LOOPS:

For "&&" both have to be TRUE for the "if" to be true.
For "||" only one has to be TRUE for the "if" to be true.



[php] <?php
if ((1 > 0) && (2 > 0)) {
echo "1 is greater than 0 AND 2 is greater than 0";
} else {
echo "1 is not greater than 0 AND/OR 2 is not greater than 0";
}
//the "if" is TRUE because BOTH are greater than 0



if ((1 > 0) && (2 > 0)) {
echo "1 is greater than 0 AND 2 is greater than 0";
} else {
echo "1 is not greater than 0 AND/OR 2 is not greater than 0";
}
//the "if" is TRUE because BOTH are greater than 0



if ((1 > 0) || (2 == 0)) {
echo "1 is greater than 0 OR 2 is equal to 0";
} else {
echo "1 is not greater than 0 OR 2 is not equal to 0";
}
//the "if" is TRUE because the first statement is TRUE even though the second is FALSE.



if ((1 < 0) || (2 >= 0)) {
echo "1 is less than 0 OR 2 is greater than or equal to 0";
} else {
echo "1 is not less than 0 OR 2 is not greater than or equal to 0";
}
//the "if" is TRUE because the first statement is FALSE but the second is TRUE.

?>[/php]


Last I would like YOU to try to make your own "if" statements and try making and messing with strings and variables too! ]Here is a zip archive of the loops, variables, and strings files. Upload them to your own site and experiment changing them. You need to make sure you understand them well.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: Sat Jan 13, 2007 6:32 pm 

Points:
The link to your zip file is broken. :)


Report this post
Top
  
Reply with quote  
 Post subject: Yep
PostPosted: Sat Jan 13, 2007 7:03 pm 

Points:
Yep, this site is slowly growing into a state of disrepair...

Everything is being updated and moving over to http://www.code2design.com. We are also adding video tutorials and other things. :D


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Registered users: No registered users


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron

Portal » Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
[
SEO MOD © 2007 StarTrekGuide ]