2. Special Data Types Resource - Reference to a third-party resource (a database, for example) NULL - An uninitialized variable Sample <?php $testing; // declare without assigning print gettype( $testing ); // NULL ?>
3. PHP’s Type Functions var_dump()- tells you a variable's type and its contents Sample <php $testing = 5; var_dump( $testing ); ?>
4. PHP’s Type Functions gettype()function - to acquire the type of any variable. If you place a variable between the parentheses of the function call, gettype() returns a string representing the relevant type (NULL, integer, string, double , boolean) Sample <?php $testing = 5; print gettype( $testing ); // integer ?>
5. PHP’s Type Functions settype()function - to change the type of a variable. To use settype(), you must place the variable to change (and the type to change it to) between the parentheses and separate them by commas Sample <?php $undecided = 3.14; settype( $undecided, double ); print gettype( $undecided ); print " -- $undecided<br />"; // 3.14 ?>
6. Operators and Expressions Operators- are symbols that enable you to use one or more values to produce a new value. A value that is operated on by an operator is referred to as an operand. 4+3 Expression- is any combination of functions, values, and operators that resolves to a value. 4+3=9 $user=you; gettype( $user); Assignment Operator - takes the value of its right operand and assigns it to its left operand $name = "matt";
7. Operators and Expressions Arithmetic Operators - The addition operator adds the right operand to the left operand, whereas the subtraction operator subtracts the right operand from the left. The division operator divides the left operand by the right, and the multiplication operator multiplies the left operand by the right. The modulus operator returns the remainder of the left operand divided by the right. Example (+)Addition (-)Subtraction (/)Division (*) Multiplication (%)Modulus
8. Concatenation Operator The concatenation operator is a single period (.). Treating both operands as strings, it appends the right operand to the left Sample "hello"." world" is equivalent to "hello world" $centimeters = 212; print "the width is ".($centimeters/100)." meters";
9. Combined Assignment Operator consists of a standard operator symbol followed by an equals sign. Example $x = 4;$x = $x + 4; // $x now equals 8 can instead be written as $x = 4;$x += 4; // $x now equals 8
10. Comparison Operators perform tests on their operands. They return the boolean value true if the test is successful and return false otherwise. This type of expression is useful in control structures, such as if and while statements Example $x=5.1 $x < 5
11. Logical Operators To test combinations of booleans Sample true || false = true true && false = false
12. Operator Precedence When you use an operator, the PHP engine usually reads your expression from left to right. Sample 4 + 5=9 4 + 5 * 2 = 18 or 4 + 5 * 2 = 14 or (4 + 5) * 2 = 18
13. Constants Variables offer a flexible way of storing data because you can change their values and the type of data they store at any time. If, however, you want to work with a value that you do not want to alter throughout your script's execution, you can define a constant. You must use PHP's built-in function define() to create a constant. After you have done this, the constant cannot be changed. To use the define() function, you must place the name of the constant and the value you want to give it within the call's parentheses. These values must be separated by a comma, like so: Example define ("CONSTANT_NAME", 42); <?php define ("USER", "Gerald"); print "Welcome".USER; ?>