MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

PHP 7 Fundamental Tutorial for Beginners – PHP Data Types

The name itself indicating, data types means type of data.

The values assigned to a PHP variable may be of different data types including simple string and numeric types to more complex data types like arrays and objects.

PHP supports total of eight primitive data types: Integer, Floating point number or Float, String, Booleans, Array, Object, resource, and NULL. These data types are used to construct variables. Now let’s discuss each one of them in detail.

Types of data types in php:

PHP data types are mainly divided into 3 types:

  • Scalar Data Types: integer, string, Floating-Point Numbers or Doubles, Boolean
  • Composite Data Type: array, object
  • Special Data Types: Null, resource

Scalar Data Types: allow us to create variables or constants; which can hold a single value.

Integer: means whole number, i.e. number without floating point

Ex: 122, 2000, -400 etc.

Double: Means decimal or float number, i.e. number containing floating Point.

Ex: 3.142, 9.8, -48.32 etc.

String: indicates a sequence of characters enclosed within pair of double quotations or single quotations i.e. Textual data.

Ex: “Hello world” , ‘Hello JavaScript’ etc.

Boolean: indicates logical or conditional result Boolean data type has two values true and false value.

Note:
integers 0 and -0, double 0.0 and -0.0, string with value “, string with value “0”, Boolean false value, an array with zero elements, the special type NULL, and XML objects created from empty tags, are considered as false in PHP.

Example:

PHP Arrays

An array is a variable that can hold more than one value at a time. It is useful to aggregate a series of related items together, for example, a set of country or city names.

An array is formally defined as an indexed collection of data values. Each index (also known as the key) of an array is unique and references a corresponding value.

Example:

PHP Objects

An object is a data type that not only allows storing data but also information on, how to process that data. An object is a specific instance of a class which serve as templates for objects. Objects are created based on this template via the new keyword.

Every object has properties and methods corresponding to those of its parent class. Every object instance is completely independent, with its own properties and methods, and can thus be manipulated independently of other objects of the same class.

Here’s a simple example of a class definition followed by the object creation.

Example:

Special data Types: allow us to make a variable point to some external resource or not to point anywhere.

NULL: indicates nothing.
A variable of type objects points or refers to another memory location; if it should not point to any memory location then we assign a value null to it.

Example:

When a variable is created without a value in PHP like $var; it is automatically assigned a value of null. Many novice PHP developers mistakenly considered both $var1 = NULL; and $var2 = “”; are same, but this is not true. Both variables are different — the $var1 has null value while $var2 indicates no value assigned to it.

PHP Resources

Indicates variable is pointing to an external resource

A resource is a special variable, holding a reference to an external resource.

Resource variables typically hold special handlers to opened files and database connections.

Example:

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Encryption using RSA public and Private Key using PHP

PHP's OpenSSL extension can create an RSA key pair, encrypt data with the public key and decrypt it with the private key. This page explains the gist…

Read More

Encryption using Public key and Private key in PHP using mySql database

This tutorial shows how to generate an RSA key pair with PHP's OpenSSL extension, encrypt form input with the public key, store the ciphertext in MySQL, and…

Read More

How to see number of emails sent using smtp in laravel

Laravel does not count or log SMTP emails by default, so a grep will only return a real number once your application writes one log line for…

Read More

What are the Authentication type in phpmyadmin which for config.inc.php

phpMyAdmin supports four authentication types, set per server with $cfg['Servers'][$i]['auth_type'] in config.inc.php: cookie (the default), config, http and signon. This page explains how each one works and…

Read More

What is opcache and Install / Configure in Linux

OPcache is PHP's built-in bytecode cache. It keeps compiled scripts in shared memory so PHP doesn't have to parse and compile the same files on every request….

Read More

PHP Code for Godaddy VPS Server SMTP Email Relay

This page shows how to send email from a GoDaddy VPS through GoDaddy's SMTP relay on port 25 with plain PHP sockets and no extra libraries. Below…

Read More