PHP Tut 4 - Printable Version +- Support Forums (https://www.supportforums.net) +-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87) +--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18) +---- Forum: PHP The Hypertext Preprocessor (https://www.supportforums.net/forumdisplay.php?fid=21) +---- Thread: PHP Tut 4 (/showthread.php?tid=8064) |
PHP Tut 4 - Minus-Zero - 06-29-2010 Credits to W3Schools for the text in quote tags and the first example. Quote:If variables are the building blocks of a programming language, operators are the glue that let you build something useful with them. You've already seen one example of an operator - the assignment operator -, which lets you assign a value to a variable. Since PHP believes in spoiling you, it also comes with operators for arithmetic, string, comparison and logical operations. Code: <html> You will notice in the code it sets its variable but as you look farther down your like Uhh wat? That is because you see this Code: // calculate difference in price Now Lets explain some of that! $diffPrice = $currPrice - $origPrice; Well this is simple its just using set variables to subtract from each other, then the resulting difference is our new variable. $diffPricePercent = (($currPrice - $origPrice) * 100)/$origPrice Ok well here you see your setting a variable again. Notice all that stuff after the " = ". Well sort of like order of operations. What it looks for is the thing it needs to do first, which is whats inside the parenthese. Oh but look their is parenthese in the parenthese. So it does the parenthese inside of the parenthese first. Which is currPrice - OrigPrice, then it will times it by 100. Finally it will divide by the OrigPrice. The rest of the code is just putting it into a table. Now lets move on to another example! If you'd like, you can even perform an arithmetic operation simultaneously with an assignment, by using the two operators together! Is that amazing or what? Here: Code: <?php Does the same thing as: Code: <?php PHP also allows you to add strings with the string concatenation operator, represented by a period. Code: <?php First thing i did was set the variables. $statement = $a.' '.$b.' '.$c.' '.$d.' '.$e.'<br />'; Ok Well basically all this did was set a variable using all the other variables..... Not much more i can say Also you can concatenate and assign simultaneously. Code: <?php First line is just me setting a variable as normal. Then there is $str .= 'n'; Well what this does is will take $str variable which was "hell" And just add an o to the end. Turning "hell" Into "hello" That is all for this tutorial Please rate and thank me! RE: PHP Tut 4 - `P R O D I G Y™ - 07-21-2010 Another thorough tutorial by you, you're working for 5 soon. Keep it up dude |