If Then Else for PHP

One of the most important syntax’s in programming is the If-Then-Else statement, it’s pretty much what the transistor does in hardware in the computer processor, it has a If then else system as well.

In PHP There are a few ways to write a If Then Else syntax:

Lets set a default value for the examples first:

If-Then-Else Syntax 1:

If-Then-Else Syntax 2:

If-Then-Else Syntax 3 (Shorthand):

In syntax’s 1 and 2 you can add a secondary condition called “else if” or “elseif”, this condition allows you to enter a secondary question to the if statement.

If-Then-Else Syntax 1 (Updated with ElseIf):

If-Then-Else Syntax 2 (Updated with ElseIf):

If-Then-Else Syntax 3 (Shorthand, Updated with ElseIf):

Regular mode using either syntax 1 or 2 is fairly easy you just add in a secondary statement called elseif while with Shorthand you need to add in a whole other if else statement into the correct position, the Shorthand works like this:

(condition ? true : false)

So for a secondary statement if that condition registers as false as it does with an elseif statement, it really is a secondary if statement if the first one didn’t pass. This is the way to make a shorthand if elseif statement, you replace the false statement on the previous example such as this:

(condition1 ? true : (condition2 ? true : false))

I usually always used the Syntax type 1 but recently I’ve gotten fond of the Shorthand method, one good example is for generating selection menus from a MySQL/MariaDB database:

This example does a MySQL connection request and a loop through the data and if the $a value matches the $row['id'] for the current row it will output the following data:

Otherwise you get this:

These are the basics of If Then Else in PHP today.

My MMO Review

The last 10 years or so I’ve been playing many different MMO’s (Massively Multiplayer Online). And many had some small good things, and then some odd limitations and other things. I will bring the games up in the order I played them and list their strengths and weaknesses, this isn’t a review about the graphics but more about how the games performed on hardware of the day when they are/were current. This mass-review I write as a coder in mind, pointing out things a coder would think about, at least one like me :)

Continue reading

Optimization

Optimizing you code is important, why? Mostly because of speed, both transfer speed and loading. So how do you go about improving the speed on your websites? There are a couple of tools that will aid you in this:

Personally i prefer YSlow these days, I used to use Google Page-speed before, but it’s not quite as good as YSlow is. They both work virtually the same way but YSlow incorporates more real world usage where as Page-speed is more optimizing to the level where it’s not really faster anymore.

Continue reading