Basic PHP

PHP is a great programming language for anyone to learn. It’s a high-level programming language which means it has a lot of “powerful,” time-saving functions that are very readable and understandable. The learning curve is much lower than other programming languages, but it also has many mature, advanced features. For the most part, we’ll be learning by example. We’ll look at a small piece of code and then dissect it. Here’s the first piece of code.

$welcomingSentence = 'Hello, world!';

We can learn a couple different programming concepts from this statement.

Code Dissection

$welcomingSentence

Variables are a way to store data. In PHP, variables start with a dollar sign. The text that follows should describe what the data is. The text is camel-cased which means that all of the words except the first are capitalized. Also, there are no spaces in variable names.

=

The equals sign is an operator. The equals sign assigns the data on the right of the equals sign to the variable.

Yes, we’re even going to dissect the single quote! Strings are always wrapped in single or double quotes. For now, we’ll just use single quotes until we need to use double quotes.

Hello, world!

The text in the single parenthesis is called a string. A string is a type of data. Numbers and objects are two other types of data. If you’re interested, you can look up all the data types, but we’ll run into each one eventually.

;

The PHP expression ends in a semi-colon. In PHP, all expressions end with a semi-colon. It’s kind of like a period. It tells PHP that the expression is done, just like this lesson.

Project

Create a PHP variable and assign a string of text to it.