PHP Basics

General

Getting Started

Scalar Types

Compound Types

Variables and Constants

If Statement

Switch Statement

switch ($variable)
{
  case 1:
    ...
    break;
  case 2:
    ...
    break;
  default:
    ...
}

Conditional Expressions

Loop Constructs

User Defined Functions

function addOne ($number)
{
  return $number + 1;
}

// illustrates a function as a procedure
// uses a default value 
function bold ($string = "leipzig")
{
  echo "<b>" . $string . "</b>";
}

// pass by reference
function doubleValue (&$number)
{
  $number *= 2;
}

// static local variable
function count()
{
  static $count = 0;
  $count++;
  return count;
}

Defined Functions

Function Reuse

Lecture Code

Write a php file that computes and prints all of the times between 0 hours and 12 hours (inclusive) when the hour hand and the minute hand of an analog clock are in alignment. The output of the php file should match this file exactly.

Solution

The clock.php file that we developed during class.


Laboratory

Do something interesting and non-trivial that uses some of today's material. If you are a Montana State student, demonstrate it during today's lab period. If you are a University of Leipzig student, either demonstrate it during today's lab period or e-mail it to Sebastian (loewe AT uni-leipzig.de) no later than the end of the day.

Valid XHTML 1.0!