Part 4: Variables in Print in PHP Programming


  1. What are the three types of PHP variables that Eli discusses?
  2. Strings, integers, and arrays. Strings are words, and are declared by $variable = "Hello World";. Integers are numbers, and are declared by $variable = 42;, using no quotation marks. Arrays are lists of items and are created by $variable = array();.

  3. What naming rules apply to PHP variables?
  4. Variables are case sensitive, so the variables $variable, $VARIABLE, and $Variable are all different variables. It is useful to keep all variables in the same style - for example, naming all of your variables with lowercase letters throughout your code. Variable names must begin with a letter or an underscore.

  5. Compare and contrast the html <br> tag in HTML and the \n in PHP.
  6. \n is the command in PHP to start a new line, however it will not work when printed within quotation marks, as the browser will read it as HTML text. the <br> tag is the HTML equivalent of the \n newline character in PHP, and will place text on two lines.

notepad++ Example Program

The link above is the sample code created with Eli's demonstration of variables and print in PHP. It shows several lines are really just variables that have been printed with various HTML formatting, and also demonstrates the importance of using the <br> tag in quotation marks to print text on two lines.