of values over time, and an unknown or designated value at any one time. In PHP, they start with a $ You do not have to give you variables a type in PHP $hello = “Hello!” basic types include integers, floats, booleans, and strings.
with letters, numbers, or _. These are also valid characters in any part of the name General Tip: Use descriptive names over short names If your variable name has more than one word, use $camelCase or $the_underscore_technique.
+ - * / modulus: % - returns the remainder of left argument divided by the right concatenation : . “adds” two strings See example1-1.php to see them in action
apples, I will give you two. Otherwise, you will give me one. [see example1-3.php] if ( $my_apples > 6 ){ $my_apples -= 2 $your_apples += 2 } else { $my_apples += 1; $your_apples -= 1; }
until that value meets a condition (part 2), doing something to that value each iteration (part 3). for( $i = 0; $i < 10; $i++){ ... } While: Iterates until a condition is met. while( $i < 10 ){ ... } See example1-4.php
when called, optionally on arguments passed to it. They can also optionally return a value. See example1-5.php function addTwoValues($val1, $val2){ $result = $val1 + $val2; return $result; }
and methods- attributes are either primitive data types or other objects, and methods are functions. Functions that act on that particular instance of the object are instance methods. Functions that act separate of the object are static methods. See example1-6.php
important practice Headaches of finding a bug can be large and numerous without testing The best time to pick up the habit is when you are learning to code
a piece of code that runs your code and asserts facts about the answer. If the assertions are true, the test passes. If they are false, the test fails. We’re going to go through example1- tests.php for examples/explanation
interests you, and let’s write the code for it Try to pick something with both attributes and methods Use Source Control! Don’t forget to write unit tests for your methods There is an example in example1-Lab.php