My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more
Brief Introduction to PHP

Brief Introduction to PHP

Anih Victor Chinecherem's photo
Anih Victor Chinecherem
·Feb 2, 2023·

4 min read

PHP programming language is one of the most used and popular programming language on the web as well as the most hated programming language click to see for yourself.

Statistically, PHP powers 78.9% of websites on the internet click to check stats.

I've been writing PHP for three years now professionally and I know that some folks stuck with PHP today because of its flexibility. There are also haters as you may know who keep saying that PHP is dead but I don't think so. PHP might not have been that efficient in the past but it doesn't mean it's dead.

I think PHP is evolving and people are building awesome stuff with it.

WHAT IS PHP

PHP is an acronym for "PHP: Hypertext Preprocessor" PHP is a scripting language that can virtually make your server-side programming smooth. If you want to learn more about PHP and what PHP can do click here

AIM

The goal of this blog series is to practically engage you in understanding basic PHP. If you are new to PHP I suggest getting an overview of the language on youtube or somewhere before you can tag along. Without any further ado, let's jump right in.

PHP Variables

variables are spot in memory or a bucket that can hold a value. This spot in memory helps to hold this value for us should we need to use it in various places. We can decide to switch the value. the spot is still there for us only the value changes.

So in PHP variables are declared with a dollar sign e.g

$name = "My name is Victor";

Now, every programming language has different types of data that can be assigned to a variable. For the record what we did here is assigning a string data type to a name variable, it is a string variable because the value was enclosed with a quotation sign.

To learn more about PHP variables and data types click here

To display our output to the browser we use

print($name); or

echo($name);

My name is Victor //result

PHP Data Types

Below is the list of PHP datatypes

  • String
  • Integer
  • Float (floating point numbers - also called double)
  • Boolean
  • Array
  • Object
  • NULL

String: this type of data is always enclosed with a quotation mark. e.g "Hi I'm a string data type" or 'Hi I'm a string data type' -> this will return an error because of I'm since we are using a single quote. we need to escape the apostrophe sign on the I'm word so that PHP can parse the string.

// to escape the apostrophe we do 

      print('Hi I\'m a string data type');

// always remember your semi-colon

Personally, I don't use single quotes when it comes to strings, I think it's best practice to use double-quotes.

// this is best practice

      print("Hi I'm a string data type"); 

// always remember your semi-colon

Integer: this type of data are numbers it can be negative or positive but just number. e.g $age = 23;

Float: data types are decimal numbers, it can be negative or positive. e.g $ratio = 2.3' $ratio = -2.3'

Boolean: data types fall into two categories namely true or false in other words it can also be represented as 0 = false or 1= true

Before you load your PHP file to the browser ensure that you have PHP installed on your machine then install XAMPP XAMPP is a software package that includes all things you need to set up a local server environment on your computer, there are other software packages that can give you a local server environment like MAMP, LAMP,WAMP, but I choose XAMPP because it's easy and does not give issues on windows. Learn how to install and use xampp

Once you have that setup you can run your PHP file on the browser to view your code output.

PS: To follow along on this series ensure that you have gone through the fundamentals of PHP as I would not be going deep on certain topics.

In the next article, I will be talking about Arrays which is the major part where most beginners get issues. I will try to be as more detailed as I can, the Array topic is actually what inspired me to start this series, so hang on and anticipate!

Thanks for reading, don't forget to share your mind about this article.