Title: variables and data types ($$$)
Course: PHP/MySQL Course

Variables

Read page 87 to the middle of 89 about variables.

Answer this question?

What character does every variable begin with in php?

- $

Globals, Super Globals

Go ahead and read the section from the text from page 89 to 90 on globals and super globals.

These will become important later when we work with forms, sessions, and cookies.

It is useful to look up each of these super globals on the php reference site:

http://us2.php.net/manual/en/reserved.variables.php

go ahead an do that, but be aware, we will not cover each of these in detail till latter in class.

Question:

To make variables avaliable across different php files you must ________ .

- make them global
- write them into a library file
- put a dollar underscore in there name
- make them a $_REQUEST variable

variables and data types

Read page 90 to 96 about data types and then answer this?

What value does a variable have if it has not been assigned a value?

- null
- NULL

Operators and Expressions

Read pages 96 (Operators and Expressions) till the end of the chapter, page 107

Notes:

p98: you will read about the normal operators + - / and * that are in other computer languages.

% is the modulus operator, it returns the integer remainder resulting from a divison. I always think of n % i with this question, if if divide n things equally amoung i people, then how many things are left over. For example if i have 11 apples to divide among 3 people, ( 11 % 3 ) then each person can get 3 apples and there will be 2 left over so 11 % 3 is 2.

The . operator is used a lot in php to concatenate strings together with other data:

$hourlyRate = 25.00; #amount per hour
$hoursWorked = 20.00; # how many hours worked
$payAmount = $hourlyRate * $hoursWorked;

echo $hoursWorked . "At " . $hourlyRate . " Earns you " . $payAmount;

would output:

20 At 25 Earns you 500

____

p99-101 You may have run into += and -= in java or C++ classes.

The are a shortcut for writing something like this

x = x + 2; can be written as x += 2;

This works for all the common operators +,-,/,*,&,. etc.

The general rule is anything that is written as

v = v o expression and be written as v o= expression where v is a variable and o is an operator in the group listed above.

_____

++ and -- are also short cuts to writing someting longer borrowed from C++:

x++ increments the value in x and x-- decrements. The resulting value when you use this in an expression is the new value of x.

++x increments the value in x and --x decrements. The resulting value when you use this in an expression is the original value of x before incrementing.

_____

p102 Pay attention to the comparison operators and how they may differ from what you learned about in another programming language.

== works different from ===

6 == "6" is true
6 === "6" is false (because they are different types, integer and string)

____

p 103: php is friendly with the logical operators allowing you to use the common ones in C++ or to use the english ones:

so or is the same as ||
and is the same as &&

note that ! is not

p 106

the __FILE__ and __LINE__ constants have two underscores before and after

Question?

Given this code:

$x = "5";
$s = "five";
$z = 2 + 3;
$y = 5;

is the following true or false?

($x === $y) or ($z == $x)

- true
- false