Definition: Data types refers to types of data that can be stored that in a variable.

Explanation: Let’s think this way, Human Being, Animals, Insects all have their own characteristics, which differentiates one from the others, same is the case for data type. They can take data to their range and perform operations accordingly. PHP has a total of eight types: integers, doubles, Booleans, strings, arrays, objects, NULL, and resources

  • Integers are whole numbers, without a decimal point, like 495.
  • Doubles are floating-point numbers, like 3.14159 or 49.0.
  • Booleans have only two possible values: TRUE and FALSE.
  • NULL is a special type that only has one value: NULL
  • Strings are sequences of characters.
  • Arrays are named and indexed collections of other values.
  • Objects are instances of programmer-defined classes, which can package up both other kinds of values and functions that are specific to the class.

N.B: By Default PHP automatically sets a data type for a variable.

Type Casting

It refers to the conversion of a data type to another. By default PHP converts the type implicitly.

Operators

Definition: Operators is the symbol that tells the computers to perform certain mathematical or logical manipulation.

Explanation: Let’s think like way, Operators sets the relation between variables. Take a look at some of operators.

Arithmetic Operators

Operators Operation It Performs Example Results
+ Addition Explicit positive sign 12 + 43 55
Subtraction Negation 20 – 5 – 3 15
* Multiplication 3*4 12
/ Division 5/2 2
% Modulo division 5%2 1
++ Post-increment Pre-increment ++a ++b increments value by one
Post-decrement Pre-decrement –a –b decrements value by one

Assignment Operators

Operators Operation It Performs Example Results
= Assign right side to left side $a = 13 $a has value 13
+= Add right side to left side $a += 2 $a = $a + 2
-= Subtract right side to left side $a -= 2 $a = $a – 2
*= Multiply right side to left side $a *= 2 $a = $a * 2
/= Divide right side to left side $a /= 2 $a = $a / 2
%= Set left side to left side modulo right side $a %= 2 $a = $a % 2

Comparison Operators

Operators Operation It Performs Example Results
< less than 5 < 6 false
> greater than 25 > 16 true
<= less than or equals to 15 <= 5 false
>= greater than or equals to 25 >= 25 true
== equals to 5 == “5” true
=== Identical 5 === “5” false

Logical Operators

Logical operators combine other logical (aka Boolean) values to produce new Boolean values. We use it mainly in combination with comparison operators

Operators Operation It Performs Example Results
&& and (8>6) && (2>3) false. both relation must be true
|| or (8>6) && (2>3) true, if any one of them is true.
! not !false true, Is true if its single argument (to the right) is false and false if its argument is true.
xor exclusive or (8>6) && (2>3) true, Is true if its single argument (to the right) is false and false if its argument is true.
and same as &&
or same as ||

This is the end of this part, I will be writing the next part of the series soon, Till then practice, practice and more practice.