PHP Primitive Data Types

PHP has 10 primitive data types including 4 scalar, 4 compound and 2 special types.

Primitive Data is a Building Block for Creating Data Structures

PHP Scalar Data Types

I am scalar and therefore I am one single value. Just like a destitute bachelor, I fly solo, no other values shall be stored.

Is it true or fale? 0 or 1? Is the user logged in (true then do something, false do something else).

$logged_user = false;

Any non-decimal number, negative or positive. The total items in the shopping cart is 12.

$total = sum($cart=>items);

Floating point numbers, doubles or real numbers.
$a = 1.234;
$b = 1.2e3;
$c = 7E-10;

A series of characters.
$random_string = "asdfaohfg adsf q2048t strings #$!FW!#%FS"

PHP Compound Data Types

I will take data, and I will grant it structure, as I am Compound, the controller of structure and aggregates.

Method of storing indexed values. More commonly used as an ordered map/associative array with key and values. Partners nicely with JSON.

$array_simple = array("David Jones", "35 years old", "Lives in Nantucket, New Jersey");
$array_typical = array("Name"=>"David Jones", "Age"=>35, "City"=>"Nantucket", "State"=>"New Jersey");

We have a class blueprint to create a bus, we can use inheritance to create bus objects painted with different colors.

class Bus{
function paintBus($color){
echo 'The color of the bus is ' . $color . '.<br>';
$red_bus = new Bus();
$school_bus = new Bus():

The color of the bus is red.
The color of the bus is yellow.

Yes, I answer to string. Just call me by name.
class CallMe{
function callMeMethod(){
echo 'you called me, I am a method as I reside in a class';
function callme_function(){
echo "you called me, I am function";
call_user_func(array('CallMe', 'callMeMethod'));

Pseudo type introduced in PHP 7.1. Accepts arrays or objects.
function iterate(iterable $iterable = []) {
foreach ($iterable as $value) {
echo $value . '<br>';
iterate(['value10 ', 'value20 ']);

PHP Special Data Types

External resources and the NULL value.

Reference to an external resource, for example, connecting to a database.

$conn = mysqli_connect(localhost,"root","admin","sales");

Representation of a variable with no value. Is case sensitive.

$variable = NULL;