Skip to content
  • About Us
  • Contact Us
  • Privacy Policy
  • Disclaimer
  • Corona Virus Stats (Covid-19)
  • Work with us
  • FB
  • LinkedIn
  • Twitter
  • Instagram.com
Tekraze

Tekraze

Dive Into Technology

  • Guides
    • Developer Guide
    • PC Guide
    • Web Guide
    • Android Guide
    • Music
    • Tutorials
  • Feed
    • Tech News
    • Shared Tech
    • Gaming Videos
    • Unboxing videos
  • Forums
    • Android Apps
    • Angular Npm Packages
    • Useful Site Links
    • Tech Queries
    • Windows OS Help
    • Web Guide and Help
    • Android Os And Rooting
    • Jhipster Discussion
    • Git & GitHub forum
    • Open Source Forum
  • Work with us
  • Toggle search form
  • Top 3 Signs That Your Beloved Macbook Needs Tuning
    Top 3 Signs That Your Beloved Macbook Needs Tuning Latest tech
  • Yoast Seo – The Seo master plugin everyone should use Tekraze
    Yoast Seo – The Seo master plugin everyone should use Product Reviews
  • Trump to end Transaction with Tencent and Bytedance
    Trump to end transactions with Tencent and Bytedance in 45 days Tech News
  • HP Rolls out New Hardware with ExpressVPN Pre-Installed 2
    HP Rolls out New Hardware with ExpressVPN Pre-Installed Guest posts
  • Is Work From Home The Most Trending Thing Now and Factors affecting ? Tekraze
    Is Work From Home The Most Trending Thing Now and Factors affecting ? Emerging Startups
  • Realme Narzo 10 Tekraze
    Realme Narzo 10 and Narzo 10A Launched Tech News
  • Alphabet of programming ;languages
    The Alphabet of Programming Languages Tech News
  • How the Best SEO Company in Sydney Shall Approach Your Project 3
    How the Best SEO Company in Sydney Shall Approach Your Project Guest posts
PHP Data Types 4

PHP Data Types

Posted on March 2, 2018February 24, 2020 By RAHUL CHANANA 2 Comments on PHP Data Types

We have learned in the last tutorial, about Reference of variable. Now, we will discuss  Data Types in PHP.

Table of Contents

  • DATA TYPES:
      •       So let’s we can first discuss about Scalar types:
      • In Scalar their are four data types:
      •      Let’s go through the examples of Scalar Data Types:
      • INTEGER:
      • Rules for integers:
      • FLOAT:
    • String:
      • The escape-sequence replacements are −
    • Boolean:
    • NOW let’s discuss Compound  types:
    • Array:
    • OBJECTS:
    • Now our last Special Types:
    • Resource:
    • NULL:

DATA TYPES:

The very first question is in our mind is that what is data type.

In simple language, if variables are container then data type is the type of container. type of container actually tells that what kind of stuff can be put in it. For example you don’t want to put cookies in a bottle similarly you don’t want to store an integer value in a variable of data type String.

Basically data types in PHP we can categorized in 3 types:

1. Scalar Types

2. Compound Types

3. Special Types

PHP Data Types 5

      So let’s we can first discuss about Scalar types:

In Scalar their are four data types:

  1. Integer
  2. Float/Doubles
  3. String
  4. Boolean

     Let’s go through the examples of Scalar Data Types:

INTEGER:

 First we will take the example of integer,

They are whole numbers, without a decimal point, like 4195. They are the simplest type .they correspond to simple whole numbers, both positive and negative. Integers can be assigned to variables, or they can be used in expressions, like so –

An integer data type is a non-decimal number between -2,147,483,648 and 2,147,483,647.

Rules for integers:

  • An integer must have at least one digit
  • An integer must not have a decimal point
  • An integer can be either positive or negative
  • Integers can be specified in three formats: decimal (10-based), hexadecimal (16-based – prefixed with 0x) or octal (8-based – prefixed with 0)

<?php

$int=”12345 <br>”;
$onemore_int = -12345 + 12345;
echo $int_var;
echo $another_int;

?>

OUTPUT:
12345

0

FLOAT:

A float (floating point number) is a number with a decimal point or a number in exponential form.

It is also called numeric data types. A number with a fractional component.

They like 3.14159 or 49.1. By default, doubles print with the minimum number of decimal places needed. For example, the code −

<?php

$float=20.2534;
echo $float;

?>

OUTPUT:
20.2534

String:

  • A string is a sequence of characters, like “Tekraze”.
  • A string can be any text inside quotes. You can use single or double quotes.
  • Singly quoted strings are treated almost literally, whereas doubly quoted strings replace variables with their values as well as specially interpreting certain character sequences.
  • There are no artificial limits on string length – within the bounds of available memory, you ought to be able to make arbitrarily long strings.
  • Strings that are delimited by double quotes (as in “this”) are preprocessed in both the following two ways by PHP −
    • Certain character sequences beginning with backslash (\) are replaced with special characters
    • Variable names (starting with $) are replaced with string representations of their values.

<?php
$abc = “PHP Tutorials on”;
$xyz = ‘Tekraze!’;

echo $abc;
echo “<br>”;
echo $xyz;
?>

 

OUTPUT:

PHP Tutorials on

Tekraze!

The escape-sequence replacements are −

  • \n is replaced by the newline character
  • \r is replaced by the carriage-return character
  • \t is replaced by the tab character
  • \$ is replaced by the dollar sign itself ($)
  • \” is replaced by a single double-quote (“)
  • \\ is replaced by a single backslash (\)

Boolean:

  • A Boolean represents two possible states: TRUE or FALSE.
  • PHP provides a couple of constants especially for use as Booleans: TRUE and FALSE, which can be used like so −

if (TRUE)
print(“This will always print
“);

else
print(“This will never print
“);

NOW let’s discuss Compound  types:

  1. Array
  2. Objects

Array:

  • An array stores multiple values in one single variable.

<?php
$arr= array(“Volvo”,”BMW”,”Toyota”);
var_dump($arr);
?>

  • In the above example $arr is an array. The PHP var_dump() function returns the data type and value:

OBJECTS:

  • An object is a data type which stores data and information on how to process that data.
  • Objects are instances of programmer-defined classes, which can package up both other kinds of values and functions that are specific to the class.

<?php
class hello {
function hello() {
$this->model = “TEKRAZE”;
}
}

// create an object
$abc = new hello();

// show object properties
echo $abc->model;
?>

OUTPUT:

TEKRAZE

Now our last Special Types:

1.  Resource

2. Null

Resource:

  • The special resource type is not an actual data type. It is the storing of a reference to functions and resources external to PHP.
  •  Resources are special variables that hold references to resources external to PHP (such as database connections).
  • A common example of using the resource data type is a database call.

 

<?php

$conn=mysqli_connect(“localhost”,”root”,”password”);

?>

NULL:

  • NULL is a special type that only has one value: NULL. To give a variable the NULL value, simply assign it.
  • A variable of data type NULL is a variable that has no value assigned to it.
  • If a variable is created without a value, it is automatically assigned a value of NULL.Variables can also be emptied by setting the value to NULL:

 

<?php
$x = “Tekraze!”;
$x = null;
var_dump($x);
?>

 

OUTPUT:

null

If you like this tutorial please share it with your friends, colleagues and with your relatives, keep visiting and be a part of the Tekraze family. If you have any problem with this tutorial please comment in the comment box and if you have any suggestion regarding this then please tell us.

Content Protection by DMCA.com
PHP Tutorials Tags:DATA TYPES, PHP, PHP Data Types

Post navigation

Previous Post: Self Driven Startups and Embedded Tech Evolving Progressively in Past Decade
Next Post: Female Founded StartUps

Related Posts

  • Introduction to PHP 7
    Introduction to PHP Web Guide
  • Variable & its Scope in PHP 8
    Variable & its Scope in PHP Developer Guide
  • PHP-Operators 9
    PHP-Operators PHP Tutorials
  • How to Install PHP XAMPP 10
    How to Install PHP XAMPP PHP Tutorials
  • Reference Variable in PHP 11
    Reference Variable in PHP PHP Tutorials
  • Develop Mobile Apps with PHP & Have Some Kik in Life 12
    Develop Mobile Apps with PHP & Have Some Kik in Life Developer Guide

Comments (2) on “PHP Data Types”

  1. Leif Rockhold says:
    April 28, 2020 at 11:54 am

    Saved as a favorite!, I really like your blog!

    Reply
    1. Balvinder Singh says:
      April 28, 2020 at 12:26 pm

      Thanks

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Advertisements

Subscribe to updates

Enter your email below to subscribe





Posts by Categories

Advertisements
  • GitHub - A Wizard Hat 13
    GitHub – A Wizard Hat Developer Guide
  • free graphic design websites for graphic designers banner in 2021
    29 Top Free Graphic Design Websites for Graphic Designers in 2021 Developer Guide
  • Things to Consider When Selecting a Mobile App Development Platform
    Things to Consider When Selecting a Mob-App Development Platform Developer Guide
  • GIMP vs PHOTOSHOP
    GIMP vs PHOTOSHOP Which one is the Designers Choice? Tutorials
  • Introduction to Git Version Control
    Introduction to Git Version Control Developer Guide
  • A simple script to create Rest API in Python with Dockerization as Bonus
    A simple script to create Rest API in Python with Dockerization as Bonus Developer Guide
  • Top Programming Languages That Largest Companies Are Hiring Developers For In 2018 14
    Top Programming Languages That Largest Companies Are Hiring Developers For In 2018 Tech News
  • How to Install PHP XAMPP 15
    How to Install PHP XAMPP PHP Tutorials

Affliate Links

Sell with Payhip

Earn with Magenet

Sell and Buy with Adsy

GainRock affiliate Program

Automatic Backlinks

Advertise with Anonymous Ads

accessily tekraze verificationIndian Blog Directory

Copyright © 2023 Tekraze.

Powered by PressBook News WordPress theme