Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

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 a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

What is CodeIgniter and use cases of CodeIgniter?

What is CodeIgniter? CodeIgniter is an open-source PHP web application framework designed to simplify and accelerate web development. It follows the Model-View-Controller (MVC) architectural pattern and provides…

Read More

What is PHP and use cases of PHP?

What is PHP? Are you wondering what PHP is and how it works? Look no further! In this article, we will explore the ins and outs of…

Read More

Complete guide on PHP certification courses, tutorials & training

What is PHP Hypertext Preprocessor is known as PHP. Many developers use PHP, an open-source server-side programming language, to create websites. In addition, it is a general-purpose…

Read More

Complete PHP with Laravel Certification Guide & tutorials

What is PHP with Laravel? PHP was visioned eventually in the fall of 1994 by Rasmus Lerdorf. PHP means Hypertext Preprocessor. It’s a extensively- used, open source…

Read More

Top 50 PHP Interview Questions and Answers

1) What is PHP? PHP is an open-source, interpreted, and object-oriented scripting language that can be executed at the server-side. PHP is well suited for web development….

Read More

Complete guide of PHP certification courses, tutorials & training

PHP is a great beginner programming language for anyone who is wanting to cross over into the coding world. Though easy to learn, it is an extremely…

Read More