My PHP journey part 2.

So we just started to tackle operators. We looked increment and decrement… now we’re going to look at comparison operators.

Comparison Operators

The way in which I am remembering how these operators work is by simply remembering – comparisons. Same as, equal to, identical to, not the same as and so on.  It’s funny, equal to is not the same as identical to.  Something worth remembering.

So the symbols and meanings are as follows.

== …. “is equal to” (ie, values are equivalent; data types may be different though)

!= …. “is not equal to”

<= …. “smaller than or equal to”

=== …. “identical to” (both value AND data type are the same)

We can use these to make decisions because they equate to true or false data types.  How and when something is allowed access or even allowed to work. We’ll get to this later with a logical operator.

So for example…

$a = 4

$b = 8 

1+ 3 == $a ….//true

2 * 4 === $b//true

…And so on.

Truthy and Falsy 

Boolean data types equate to True and False – and these will determine whether the rest of script will run.  They have some simple atrributes that are worth remembering.


  • Boolean false
  • the integer 0 (zero) and float 0.0
  • null
  • the string “0”
  • an empty string
  • an empty array


  • Boolean true
  • Any string apart from the “falsy ones”, eg “string”
  • Integers apart from the above – e.g. 1, -123.45

 Conditional Statements 

PHP uses conditional statements to decide what to next.  It evaluates, operates and thinks, if this is X then… do something, if it’s not do something else

The main conditional statements are:

– if

– if…else

– if…else if

– switch

A piece of conditional statement code looks like this.

if ( expression ) {
piece of code here which equates to true or false will run

Think about this… You’re literally writing your own logic.  Is something not equal to… you could write it that if something is not equal too, but is true? For example:


$name = ‘Bill’;

if( $name != ‘Bert’ ){

echo ‘You’re not Bert!’;  //This will echo because != means ‘not equal to’ 


You can invert or shortcut the expression by making it false… you do this by putting ! in front of it. 

So it’ll look like this:

$weather = ‘bad’;

if( ! ($weather == ‘good’) ){  

echo ‘take your umbrella!’;

}  //To make this clear, weather equals ‘bad’ we know this – so this reads ‘if the weather is not the same as good, go get my umbrella.  It’s a double negative// 

Okay so you’ve written the script, and now you’ve written details on whether it works or not.  So what if you script comes to an end too suddenly? You can put in an else statement. So if something doesn’t happen at the if stage, something else will happen.

For example

$name = ‘admin’;

if( $name = = ‘Julie’){

echo ‘Hi Julie, how are you?’;
else {
echo ‘Welcome, user’;

Are you following me so far? 

Logical AND && and Logical OR ||

A logical AND is represented as a double ampersand.  If you have two or more expressions within you IF statement  it’ll mean that both of those expressions will have to evaluate to true for it to run.

For example:

$x = 3; 
$y = 5; 

if ( $x < $y && $y < 10 ){ 

echo $y


Both of those parts equate to true so on a blank screen you’ll see the number 5. If one of them didn’t equate to true you wouldn’t see anything.

A logical OR is represented by a double pipe || These symbols are alot easier to please as you only need one of the expressions to equate to true.  

Okay that’s enough brain melting for one day!

The structure of an HTML document

When you’re writing a HTML document, there is a structure to follow.  You can create these documents using a simple text editor such as Notepad or Notepad++

The HTML document looks like this…


This looks pretty complicated at first glance. But let’s break it down…

<!DOCTYPE HTML> Very simple, this is just what the document type is, it’s a html document.

<HTML></HTML> This is an open HTML tag, this surrounds the document, it’s all it does. It goes at the top and at the bottom.

<HEAD></HEAD> Here you would put all of your meta data, java or styling into the web page.  Don’t worry, we’ll come to those later.

<TITLE></TITLE> This is the title of the page, this is what would appear at the top of your browser window.

<BODY></BODY> This is the actual content of the document.

Once you save this, be sure to save it with a .html suffix, so for example…. “something.html”

Read up on how to create things inbetween the <BODY> tags here.

An introduction to HTML

HTML stands for…

Hyper Text Mark-up Language.

HTML is made up of…

– Text content (what you see)
– Markup (what it looks like)
– References to other documents (videos, images…etc)
– links to other pages

Let’s get started.

The HTML markup – tags and elements

<name> content </name>
HTML can be made up of opening tag and a closing tag

The whole of the above put together is known as an element.

<b>Contents</b> – b for bold.
<em>Contents</em> – em for emphasis or italics.

HTML Attributes

Attributes have a name and value.

For example:

<tag attr=”value”>Contents</tag>

The most common attribute, is the link.

<a href=”“>derp</a>

<a> stands for anchor.
href‘ is the attribute name, ‘‘ is the value.

Image tags

<img> – images’

SCR is the source of the image, either your server or someone else’s.
ALT is the text which isn’t displayed when the image doesn’t load. Believe it or not, it’s actually for blind people.

The whole image tag looks like this…

<img src=”url or a link goes here” alt=”text”>

There is no closing end tag. This is known as a void tag, there is no content, but there is, if you know what I mean!

Images appear in-line with text, unless specified.


You can force lines to show underneath each other and create a whitespace or a line.

<br> – again it’s a void tag.

You can also use a <p> tag. P for paragraph. This is not a void tag. It looks like this.


Why do we have two different ways of doing the same thing?

The <b> tag is inline, everything is line based. Where as <p> is known as a block tag and that creates a box around the text and pushes things outside of it down a line.

SPAN and DIV’s

<span>text</span> is an inline tag.
<div>text</text> is a block tag.

They are both ways of keeping content in shape, similar to the <p> and <br> tags.

A <div> will create a new line and push everything down a peg. Much like the <p> tag.

Want to see what an HTML document looks like? Click here.