Hello guys, thank you for returning to my post, I have put an extra work to make sure my post is well understandable to my lovely readers who wish to learn php programming languages. And in this post we will discuss a very important aspect of most Programming languages which is 'Data Types and variables in PHP programming'. In my last post we discussed about the differences between Procedural programming and object oriented programming. If you have not read that you can read that here or you continue reading.

PHP Variables

 So before we dive in let's list out the points we will discuss today.

  • What are Data types in php
  • Different Data types in php
  • What are Variables
  • Rules in writing PHP Variables

What are Data types in PHP

Data types in programming are used most of the time when writing codes. It is something you can't do without in php programming, because PHP is sort of input, storing and displaying data to the viewers (client side) and there are lots if data in PHP programming but all are classified into four (4) different types.

Different Data types in PHP programming language

We have over 10 primitive data types in PHP. But all this 10 has been classified under four categories, which are the Scalar data types, Compound data type, Special data type and Pseudo-Type.S

ScalarData type

These includes: Strings, Integer, Float, Boolean

Compound Data type

These includes: Array, Object, Callable, Iterable

Special Data type

These includes: Resource, Null

For the purpose of this post we will be focusing on the scalar data type.

Scalar Data Types

Scalar Data Types are the ones we use regularly when it comes to PHP programming and it consist of strings, integers, floats and booleans. Let's start with strings
Strings: strings are data types that are wrap in a quotation mark. And there are two ways of doing it. Either in double quotation mark ("x") or a single quotation mark ('x')
Example:
echo 'I love PHP';
echo "10";
Integers: they are written as whole numbers without a decimal point after the whole number
Example:
echo 10;
Bear in mind, if the number 10 is wrapped in a quotation mark, it will appear as 10 but it will be stored as string data type.
Float: these are numbers with decimal point.
Example:
echo 10.89;
Boolean: A boolean is just a true or false statement. And it is use quite often when writing codes.

These are the basic Knowledge we should have on scalar datatypes in other post we will discuss about other datatypes we have in programming.

Now let's move on to Variables

What is Variable

Variables is an important aspect of all programming languages as it is use to store data in a container which are later use while coding. Variables are common to all programming and it is something you will use quite a lot in php. A name can be given to the variable which a value (or data) is assign to it
$variable = value;

Rules in writing Variables

There are few rules to note before declaring a variable in PHP
  1. The '$' character is used to declare a variable in php
  2. The variable name must begin with a letter of an alphabet or an underscore (e.g $variable or $_variable)
  3. A variable name can only contain a-z, A-Z , 0-9 or _ (underscore)
  4. Spaces are not allowed in PHP variable. Where your variable name has more than one word, you can separate it with an _ (underscore) or you capitalize the first letter from the second word (e.g $variable_name or $variableName) 
  5. Variable names in PHP are case sensitive.
Without following the rules your variables are invalid which might lead to an error while running your code. I hope you enjoyed the post. If you need a private to tutor to guide throughout PHP course contact me on Whatsapp @ +2348076839855. And don't forget to leave a comment below thanks.