3. What the sessions are
✽ Somewhere to admit lack of
understanding
✽ Covering areas missed in workshops
✽ Helping you understand programming
theory – critical!
✽ Focussing on the “why” over “how”
✽ A launch pad for further learning
4. And what they aren’t
✽ Quick fix for The Station
• Will provide examples of when to use techniques in
context
• Will not provide code to copy & paste
✽ Easy
• PHP takes time & effort to learn
5. These go without saying
✽ Provide your own equipment
• We might not always be in the labs
• I can’t provide individual web space
✽ Don’t piss about
• Please only come if you genuinely want to learn
• I won’t waste my time or yours
10. What is PHP?
✽ Stands for PHP: Hypertext Preprocessor
• Yes, a recursive acronym. Funky!
✽ Run directly on the web server
• Windows, Linux, and Mac
✽ Makes web pages dynamic
• Calculations, database interaction, etc.
✽ Latest version is PHP 5
• Introduces features not supported in PHP 4
11. Basic PHP process
User's Browser
Web Server (Apache)
PHP Engine
MySQL Database
19. Comment everything
✽ // comments a single line
✽ /* text */ comments multiple lines
✽ Helps with learning
✽ Make comments meaningful
• Explain in detail exactly what the code does
✽ Saves time when debugging
✽ Will save your arse many times
20. Naming conventions
✽ camelCase
• Always start with a lowercase letter
• Capitalise the first letter of any further words
✽ Meaningful names
• ShowProfile() rather than function1()
• Makes code readable at a glance
23. General syntax
✽ Wrap all PHP within <?php and ?> tags
• Tells server that the code within is to be run through
the PHP system
✽ End every line with a semicolon;
• Ok, not every line but enough to use that rule
• Lets the PHP system know where a line of code ends
• Most rookie errors are caused by forgetting semicolons
24. General syntax
✽ Use $variables to store data for later
• Variables are always preceded with a $ symbol
• They can’t begin with a number
• Any type of data can be stored inside a variable
✽ Echo and print
• Used to output data to the browser
• Negligible difference in performance between the two
• Most programmers use echo
25. Data types
Name Short name Notes
Boolean bool Truth value, either true or false
Integer int Whole number (eg. 5)
Floating point float / double Decimal fraction (eg. 1.7)
String str Series of characters, usually text,
enclosed in quotation marks
Array arr Used to store multiple pieces of data
in one place
26. Assignment operators
Operator Example Notes
= $a = 1+4; Assigns the left operand (variable) to
the value on the right
+= $a += 5 Adds the value on the right the
existing value of $a
-= $a -= 5 Subtracts the value on the right from
the existing value of $a
.= $a .= ‘Hello’ Appends the value on the right to the
existing value of $a, mainly used with
strings
27. Arithmetic operators
Operator Name Notes
-$a Negation Opposite / reverse of $a
$a + $b Addition Sum of $a and $b
$a - $b Subtraction Difference of $a and $b
$a * $b Multiplication Product of $a and $b
$a / $b Division Quotient of $a and $b
$a % $b Modulus Remainder of $a divided by $b
28. Comparison operators
Operator Name Notes
$a == $b Equal True if $a is equal to $b
$a === $b Identical True if $a is equal to $b, and are of
the same data type
$a != $b Not equal True if $a is not equal to $b
$a !== $b Not identical True if $a is not equal to $b, or they
are not of the same data type
$a < $b Less than True if $a is less than $b
$a > $b Greater than True if $a is greater than $b
$a <= $b Less than or True if $a is less than or equal to $b
equal to
$a >= $b Greater than or True if $a is greater than or equal to
equal to $b
29. Increment & decrement
Operator Name Notes
++$a Pre-increment Increase $a by one then return $a
$a++ Post-increment Return $a then increase $a by one
--$a Pre-decrement Decrease $a by one then return $a
$a-- Post-decrement Return $a then decrease $a by one
30. Logic operators
Operator Name Notes
$a and $b And True if both $a and $b are true
$a && $b And True if both $a and $b are true
$a or $b Or True if $a or $b is true
$a || $b Or True if $a or $b is true
$a xor $b Xor True if $a or $b is true, but not both
!$a Not True if $a is not true
31. Operator roundup
✽ PHP uses the same operators as most
major programming languages
✽ = does not mean ‘equal to’
• = is used to assign a value
• == means ‘equal to’
32. Further reading
✽ PHP.net data types documentation
• http://www.php.net/manual/en/
language.types.intro.php
✽ PHP.net operator documentation
• http://www.php.net/manual/en/
language.operators.php
✽ PHP.net type comparison tables
• http://www.php.net/manual/en/
types.comparisons.php